Re: Names of static types
- From: Thomas Hawtin <usenet@xxxxxxxxxxxxxxxxx>
- Date: Mon, 28 Nov 2005 13:44:37 +0000
Stefan Ram wrote:
I have noticed a difference in report style between the following error messages:
interface A {} interface A_ {} class B implements A, A_ {} class C implements A, A_ {}
public class Main { static void f( final java.lang.String s ){} public static void main( java.lang.String[] args ) { f( Math.random() < 0.5 ? new B() : new C() ); }}
Main.java:49: f(java.lang.String) in Main cannot be applied to (java.lang.Object&A&A_) { f( Math.random() < 0.5 ? new B() : new C() ); }} ^ Here, one can notice that "java.lang.Object" is being mentioned. If "A_" is removed, one might expect "java.lang.Object&A" as type, but gets only "A":
Presumably so as not to give prominence to one interface over another. The first type mentioned in an intersection type is the only one that can be a class and is used for erasure.
interface A {} class B implements A {} class C implements A {}
public class Main { static void f( final java.lang.String s ){} public static void main( java.lang.String[] args ) { f( Math.random() < 0.5 ? new B() : new C() ); }}
Main.java:45: f(java.lang.String) in Main cannot be applied to (A) { f( Math.random() < 0.5 ? new B() : new C() ); }} ^ Why is "java.lang.Object" dropped now? Or, why was it mentioned in the first case?
And why can I not declare variables of such "&"-types?
You can declare a generic parameter using &. I guess there wasn't sufficient reason to allow it for variable declarations. I don't know off hand what kind of further mess to the grammar it would make.
interface A {} interface B {}
public class Main { static void f( final java.lang.String s ){} public static void main( java.lang.String[] args ) { A&B a; }}
How are these static types (in parentheses and with "&") called, which are mentioned in error message, but can not be used in the source code?
OK, if this was needed, I could write
interface C implements A, B {} (...) C a;
You can write:
<T extends A&B> void fn(T t) {
...
}(Which will produce a method with erasure void fn(A).)
Tom Hawtin -- Unemployed English Java programmer http://jroller.com/page/tackline/ .
- Prev by Date: Re: JUnit et al approach - criticisms
- Next by Date: ArrayList gives StackOverflowError in 1.5
- Previous by thread: generics question.
- Next by thread: Re: Names of static types
- Index(es):
Relevant Pages
|