This is the mail archive of the kawa@sources.redhat.com mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Class types


Chris Dean wrote:

How do I get the class of a Java type without generating a warning?
This, for example, gives a warning:

  (define (foo)
    (invoke <java.util.Date> 'getClass))

  % java kawa.repl --warn-undefined-variable -C Foo.scm
  (compiling Foo.scm)
  Foo.scm:11:11: warning - no declaration seen for <java.util.Date>

It's probably reasonable to not emit a warning in these cases, for symbols that match |<CLASSNAME>| where CLASSNAME is an existing class. I don't know how eeasy it would be to fix this. If you report it as a bug I'll take a look when I get a chance.

In any case, it probably doesn't do what you expect.  The name
<java.util.Date> is bound to a gnu.bytecode.ClassType instance,
so invoking getClass would get you gnu.bytecode.ClassType.class,
*not* java.util.Data.class.  If Java had an "abstract Class"
interface that also covered non-realized types, then we might
be able to have <java.util.Date> evaluate to a Class rather
than a Type, and you'd have what you need.  (JDK 1.5 does have
a Type interface, though it doesn't have any methods.)

Dominique's alternative has the same problem.

> The best way might be to call Class.forName( "java.util.Date" ),
> but if Kawa has an existing variable that has the class I'd prefer
> to use that.

Well, there is:

#|kawa:1|# (invoke <java.util.Date> 'getReflectClass)
class java.util.Date

Of course one might prefer to not generate the ClassType
object at runtime.
--
	--Per Bothner
per@bothner.com   http://per.bothner.com/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]