Hello,
This thread is similar to the one posted
here, but more specific to Generics.
Anyhow. As mentioned in the other thread, I am in a group working on building a resolution algorithm for Java.
For example "String" would resolve to a class in java.lang, ( Unless there was an inner class called "String" in the current context, or some other weird corner case)
Anyhow, it seems like 98% of the resolution only took a day to complete... but the last 2% are weird corner cases and are taking weeks.
I currently have an example which I cannot find the specification in the JLS. In Netbeans (and from the command line) i get 1 answer, and from Eclipse - i get another answer.
Small example of what i am saying:
public class Foo<A>{
public static class A{}
A myA; // What is "A" here? is it the Generic <A> or the static class A?
// Java & Netbeans say it is the Generic, Eclipse says the class.
}
Netbeans & java seem to treat Generics more like a "Variable" (which obscures Types).
Whereas Eclipse treats Generics more like a "Type" (which is shadowed by a more local Type)
The JLS says that generics are a "Type Variable" as far as i can tell.
In case you were curious, here is a working Example of obscuring:
public class Example1 {
int [] A = new int[10]; // the field "A"
void myMethod(){
static class A{static int length = 5;} // declaration of class inside the scope "myMethod()"
System.out.println(A.length); // this "A" is the field due to obscuring.
}
public static void main(String [] args)
{
new Example1().myMethod(); // prints 10, even though the class is in "more local",
//because Variables obscure Types with the same name. (when they both could be used)
}
}