ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ozzy Espaillat" <>
Subject RE: [cinjug] Get class name in static context
Date Sat, 24 Mar 2001 01:27:25 GMT
Static methods can not be overridden, so this will not work. It will always
call the static method specified in the signature. i.e.
  Super a = new Sub();
assuming that both Super and Sub implement
  public static String staticMethod()
then the static method in Super will be called even though the object a is
of type Sub.

I'm not sure what the intent is, maybe you can supply some code to show what
you mean. But if you don't have an object of any kind then you might be
stuck with getting the class name from an outside source i.e. System
property or property file.

-----Original Message-----
From: Robert K Casto []
Sent: Friday, March 23, 2001 1:52 PM
To: Mills, Maurice;; Ant-User (E-mail); Jboss
Subject: RE: [cinjug] Get class name in static context

I think your best bet is to declare a static method
inside the class that returns a string. Subclasses
can override this static method so that you have the
right string coming back depending on which class
you are using. Because the method is static and the
value returned in the method is static, it should
work and be setup at compile time. If this is still
too late for what you want to do, then I don't have
any ideas that could help you.

Robert Casto

-----Original Message-----
From: []On
Behalf Of Mills, Maurice
Sent: Friday, March 23, 2001 4:16 PM
To: ''; Ant-User (E-mail); Jboss (E-mail)
Subject: [cinjug] Get class name in static context

Sorry, to the Ant and JBoss lists, but the response is quicker from you.

I am trying to get the name of a class during static initialization.
Normally, you do this.getClass().getName(), however getClass() is not static
and therefore can not be called from a method, or initialization.

Does anyone know how to do this?
To find out more about this mailing list including how to unsubscribe,
send the message "info cinjug" to

View raw message