Talk:Program name

From Rosetta Code
Revision as of 01:32, 6 August 2011 by rosettacode>Fwend (propose using reflection for Java entry)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Java entry

The Java entry is kind of funny because it requires you to type the name of the class in order to print it. Then you might as well print it directly. It really should be using reflection. I've never used reflection in Java, but a after a quick glance at the documentation, I came up with this.

<lang java>public class Test {

  public static void main(String[] args) {
      Class c = new Object().getClass().getEnclosingClass();
      System.out.println(c.getName());
  }

}</lang>