Skip to Main Content

Java Development Tools

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!

Code not compiling with java7 but compiling with java6

955312Aug 12 2012 — edited Aug 15 2012
Hello all,

I have following class:
public class StrangeClass<T extends StrangeClass<S, T>, S extends StrangeClass<T, S>> {

public static void main(String[] args) throws InstantiationException, IllegalAccessException {
System.out.println("test");
}
}

It's compiling with eclipse (Java 7) and with java 6u33 (oracle) but not compiling with java 7u5 (oracle)

StrangeClass.java:1: error: type argument S is not within bounds of type-variable T
public class StrangeClass<T extends StrangeClass<S, T>, S extends StrangeClass<T, S>> {
^
where S,T are type-variables:
S extends StrangeClass<T,S> declared in class StrangeClass
T extends StrangeClass<S,T> declared in class StrangeClass
1 error

Do you think it's a bug or expected behavior?
This post has been answered by gimbal2 on Aug 13 2012
Jump to Answer

Comments

EJP
I'm inclined to agree with the Java 7 compiler here. Did you really mean to put S and T back to front in the specification of T?
955312
As name of the class says it's strange one...
It's just stupid example - more interesting is change of compiler behavior...
If it should not compile why is it compiling under java 6?
gimbal2
Answer
Because they're two separate things? Java 7 is NOT simply an "upgrade" from Java 6, its a new platform. Therefore things can and will be different.

Might in this case simply be that a bug in the compiler was plugged though.
Marked as Answer by 955312 · Sep 27 2020
955312
Thank you for answer.
1 - 4
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Sep 12 2012
Added on Aug 12 2012
4 comments
517 views