R
Reinhard B.
Hello!
Here is a bug, that all versions of SUN java 1-5-0 compilers seem to have.
The bug is, that a class, extending a base class, cannot be compiled
(because of a (wrong) error message), except you compile
both base class and sub class together.
Try this:
Write to classes, store them in appropriate files:
--------------------Base.java--------------------
public class Base {
protected class Inner <T> {
}
protected Inner<String> constructInnerOfString (String s) {
return new Inner<String>();
}
}
--------------------/Base.java--------------------
--------------------Sub.java--------------------
public class Sub extends Base {
private Inner<String> innerStr = constructInnerOfString("");
}
--------------------/Sub.java--------------------
Now compile:
javac -classpath . Base.java Sub.java
It works.
Now compile only the sub class:
javac -classpath . Sub.java
Ooops, you will get this (wrong) compiler error message:
Sub.java:4: incompatible types
found : Base.Inner<java.lang.String>
required: Base.Inner<java.lang.String>
private Inner<String> innerStr = constructInnerOfString("");
^
1 error
The problem seem to occur every time, you assign it to a variable.
If you assign the variable 'innerStr' in a constructor, you will get it,
too.
If you just call the method constructInnerOfString(...), you will get it
not.
Is this compiler bug known?
Or is it a new one?
Does anybody know anything about it?
Greetings
Reinhard Bellmann
Here is a bug, that all versions of SUN java 1-5-0 compilers seem to have.
The bug is, that a class, extending a base class, cannot be compiled
(because of a (wrong) error message), except you compile
both base class and sub class together.
Try this:
Write to classes, store them in appropriate files:
--------------------Base.java--------------------
public class Base {
protected class Inner <T> {
}
protected Inner<String> constructInnerOfString (String s) {
return new Inner<String>();
}
}
--------------------/Base.java--------------------
--------------------Sub.java--------------------
public class Sub extends Base {
private Inner<String> innerStr = constructInnerOfString("");
}
--------------------/Sub.java--------------------
Now compile:
javac -classpath . Base.java Sub.java
It works.
Now compile only the sub class:
javac -classpath . Sub.java
Ooops, you will get this (wrong) compiler error message:
Sub.java:4: incompatible types
found : Base.Inner<java.lang.String>
required: Base.Inner<java.lang.String>
private Inner<String> innerStr = constructInnerOfString("");
^
1 error
The problem seem to occur every time, you assign it to a variable.
If you assign the variable 'innerStr' in a constructor, you will get it,
too.
If you just call the method constructInnerOfString(...), you will get it
not.
Is this compiler bug known?
Or is it a new one?
Does anybody know anything about it?
Greetings
Reinhard Bellmann