Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Scoping error in prototype?

843793Dec 13 2002 — edited Mar 27 2003
I believe there are some scoping bugs in the 1.3 prototype compiler.

First, note that this is illegal:
class A { interface I {} }
class B extends A implements I {}
Although B inherits I, I is not in scope for the header of B.

Next, consider
class A { interface I {} }
class B extends A implements A.I {}
The compiler now accepts this example, since A is in scope, and A.I exists.

Now, what about
class A { interface I {} }
class B extends A implements B.I {}
This should also compile (for the same reason as the last example), but the prototype compiler rejects it saying I does not exist! This is the first bug.

We move on to this example:
class A { interface I {} }
class B<T extends I> extends A {}
The prototype compiler accepts this example. But remembering the first example, I is not yet in scope in the class header, so this should be rejected. Second bug.

To make matters more confusing:
class C<T> {
  class T {}
  T t;
}
What is the type of t? The prototype compiler accepts this, and gives it type Object (as the erasure of parameter T) rather than C.T.

On the other hand,
class C {
  <T> void m() {
    class T {}
    T t;
  }
}
Again, what is the type of t? The prototype compiler rejects this, stating that local class T conflicts with method type parameter T. Based on consistency, either the previous example or this example has a bug. I would prefer that the previous example be a compile error like this example is; if a type parameter and nested type share the same scope, they should not share the same name.

Comments

Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Apr 24 2003
Added on Dec 13 2002
5 comments
89 views