由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Java版 - Question: reflection and generics
相关主题
a question on interfaceZT: 关于性爱的多线程问题研究(一)
一个event model的概念级的问题问个Thread 的问题,java certificate里的
how to copy an Object?●●●●紧急求助JAVA初级问题,今天project due●●●●
can applet implements runnable?能这么 create thread 吗?
SOAP over SMTPimplements runable 和 extends thread
请问有没有generic的array几个问题
Re: How to showStatus in Applet?一个基本问题。
Re: connection pool关于inner class的继承
相关话题的讨论汇总
话题: date话题: public话题: object话题: helloimpl话题: class
进入Java版参与讨论
1 (共1页)
s***8
发帖数: 1136
1
I have the following generic interface:
public interface GenericIntf {
public T hello(T);
}
and an impl class:
public class HelloImpl implements GenericIntf {
public Date hello(Date d) {
return d;
}
}
When I reflect on HelloImpl class to get all methods with HelloImpl.class.
getMethods(), I got 2 methods, instead of 1:
public Date hello(Date);
public Object hello(Object)
I was expecting to see the first one (the one that has resolved to the
actual Date type). Is this expected
q*********u
发帖数: 280
2
看看doc,
getMethods
public Method[] getMethods()
throws SecurityException
Returns an array containing Method objects reflecting all the public member
methods of the class or interface represented by this Class object,
including those declared by the class or interface and those inherited from
superclasses and superinterfaces. Array classes return all the (public)
member methods inherited from the Object class. The elements in the array
returned are not sorted and are not in any

【在 s***8 的大作中提到】
: I have the following generic interface:
: public interface GenericIntf {
: public T hello(T);
: }
: and an impl class:
: public class HelloImpl implements GenericIntf {
: public Date hello(Date d) {
: return d;
: }
: }

s***8
发帖数: 1136
3
Thanks!
I've omitted methods inherited from Object. The part I don't understand is,
why hello method appears twice. Aren't they the same method, since
HelloImpl just implements the same method declared in GenericIntf?
If I don't use any generics, let HelloImpl implement Runnable interface, the
run() mehtod only appear once when reflecting on HelloImpl.
q*********u
发帖数: 280
4
I believe T yourMethod() and String yourMethod() are diferent.
According to 'Thinking in Java', I remember before 1.5, java use generic '
Object' as 'T';

is,
the

【在 s***8 的大作中提到】
: Thanks!
: I've omitted methods inherited from Object. The part I don't understand is,
: why hello method appears twice. Aren't they the same method, since
: HelloImpl just implements the same method declared in GenericIntf?
: If I don't use any generics, let HelloImpl implement Runnable interface, the
: run() mehtod only appear once when reflecting on HelloImpl.

s******n
发帖数: 876
1 (共1页)
进入Java版参与讨论
相关主题
关于inner class的继承SOAP over SMTP
线程问题。请问有没有generic的array
Object比较Re: How to showStatus in Applet?
新手问一个多线程的问题Re: connection pool
a question on interfaceZT: 关于性爱的多线程问题研究(一)
一个event model的概念级的问题问个Thread 的问题,java certificate里的
how to copy an Object?●●●●紧急求助JAVA初级问题,今天project due●●●●
can applet implements runnable?能这么 create thread 吗?
相关话题的讨论汇总
话题: date话题: public话题: object话题: helloimpl话题: class