• Post Reply Bookmark Topic Watch Topic
  • New Topic

Compiler bug? import static with a overloaded method  RSS feed

 
Marky Vasconcellos
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.. i post this on a Brazilian forum a time ago.. and i want to know why its happen..

I'll post a example cause its more simple than explain.

Class A:



Class B:


why te line 'clean(this)' war this error?



But its is applicable to clean(Container c) who is imported static.

Of course.. using the name of the class is possible invoke properly.

This:


Should be:


Its not so important to me but i'm very curios.
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since a method by name clean is also defined in the class B, the compiler thinks that you are trying to refer to this method.
I could not find a document that states it but it looks like the method definition in the local class precedes the static import.
In my opinion, this makes more sense to me and makes the code more intuitive.
 
Marky Vasconcellos
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah.. i couldnt find any document to say this.. this is why i post.

thank you.
 
Vlado Zajac
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe it is defined here (JLS - Shadowing Declarations):

A declaration d of a method named n shadows the declarations of any other methods named n that are in an enclosing scope at the point where d occurs throughout the scope of d.
 
Campbell Ritchie
Marshal
Posts: 56578
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vlado Zajac wrote:Maybe it is defined here (JLS - Shadowing Declarations) . . .
Yes, I think you are right: well done finding that. It is hardly easy to understand, though.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!