Re: Names of static types



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/
.



Relevant Pages

  • Re: Hashtable remoting issue handling a struct, Why?
    ... you need to add the files to the server so the client and server see ... > public static void Main ... > BaseRemoteObject obj = ... > public class RemInfo: BaseRemoteObject ...
    (microsoft.public.dotnet.framework.remoting)
  • Re: Beginner interface question
    ... be a bit 'fiddly' casting to the interface type to call certain ... public class Oblong:IShape ... static void displayInfo ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: take a look ... its basic but its mine, all mine!!!
    ... private static void out{ ... Swing GUI components should be constructed and modified on the Event Dispatch Thread. ... public class Runner implements Runnable { ...
    (comp.lang.java.help)
  • Re: A question related to type casting
    ... but I do feel that the Java implementation is inferior to the C# implementation. ... What should makeNewElement be making a new thing of? ... public class BigGwhere T: ... private static void Analyze ...
    (comp.lang.java.programmer)
  • Re: take a look ... its basic but its mine, all mine!!!
    ... private static void out{ ... Swing GUI components should be constructed and modified on the Event Dispatch Thread. ... public class Runner implements Runnable { ...
    (comp.lang.java.help)