Latest Thinking

Howard Lovatt howard.lovatt at gmail.com
Wed Jun 23 20:27:23 PDT 2010


Can't you just qualify the name, e.g.:

class Main {
  static String String(String String) { return String; }

  public static void main(String... notUsed) throws Throwable {
    String String = "String!";
 //   MethodHandle variable = MethodHandles.insertArguments(
 //           MethodHandles.lookup().findStatic(
 //                   Main.class,
 //                   "String",
 //                   MethodType.methodType(String.class, String.class)),
 //           0,
 //           String);
    MethodHandle variable = #String(String);
    System.out.println("variable.() = " + variable.<String>invokeGeneric());
 //   MethodHandle type = MethodHandles.lookup().findStatic(
 //           Main.class,
 //           "String",
 //           MethodType.methodType(String.class, String.class));
    MethodHandle variable = #String(java.lang.String);
    System.out.println("type.( String ) = " +
type.<String>invokeGeneric(String));
  }
}

Isn't this already covered in JLS 6.5.2?

  -- Howard.

John Rose john.r.rose at oracle.com Tue Jun 22 17:17:44 PDT 2010 wrote:
> On Jun 22, 2010, at 4:24 PM, Howard Lovatt wrote:
>
> > I don't think there is confusion between a type name and a value,
> > therefore proposed syntax OK (but maybe not the preferred). If you
> > want a class you have to append '.class'.
>
> Sorry, that would be a breaking change to the language, not an extension.  The rules for identifier resolution are exquisitely balanced, and cannot be compatibly extended in this way.
>
> // $ javac Foo.java && java Foo
> // String! and String2!
> class Foo {
>     public static void main(String... args) {
>         String String = "String!";
>         String String2 = "String2!";
>         System.out.println(String + (String)" and "+ String2);
>     }
> }


More information about the mlvm-dev mailing list