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.
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';
A syntax question when writing generic sorted linked list type:
How to specify that the implements comparable interface so it knows the
sense of "larger"/"smaller" ?
I see. It compiled successfully when I changed the pop() method in the stack
class with generic type.thanks.
public int pop()>>>>>>>>>>>public E pop(), then invoke public E remove().
One more question, how to deal with null pointer exception problem with
doublyLinkedList- type stack after I pop all the elements.
It shows error at "((DLNode)target.getSuccessor()).setPredecessor(target.
getPredecessor());"
My silly solution is to push one more element when stack.isEmpty to avoid
the situation. ... 阅读全帖
No, all generics are erased after compiling. There is no T. Anything you can
get you must get from stuff that you have at runtime.
Think about it, after type erasure your class looks like this:
public class GenericReflection
{
private Object object;
//---- get/set ---
public void setObject( Object v ){ object=v; }
public Object getObject(){ return object; }
//---- is it possible to get the class for the object? ----
public Class getObjectClass()
{
Class retval = null;
No, all generics are erased after compiling. There is no T. Anything you can
get you must get from stuff that you have at runtime.
Think about it, after type erasure your class looks like this:
public class GenericReflection
{
private Object object;
//---- get/set ---
public void setObject( Object v ){ object=v; }
public Object getObject(){ return object; }
//---- is it possible to get the class for the object? ----
public Class getObjectClass()
{
Class retval = null;
水平有限,我不敢说对错,只是聊聊自己看法而已
" Class cls = null;// 我改成Class extends AudioDevice>对吗?" 你是要变成:
Class extends AudioDevice> cls = null; 对吗?
如果是,我感觉是有问题。按我的理解,Generic 是用来 define Class and method,
只在 compile time 的时候有用,在 run time 的时候是没用的。上面的 statement
是在 declare a reference ?应该是不能 compile 吧?
1, too old, it is not updated for long time, you can redo it in generic if
your company used it a lot, but in some company that means get legal
department involved to review the licence, pain in the butt.
2, public T[] toArray(T[] a), but as you said, not simple as your code.
You can't. T doesn't exist at runtime. It's an illusion. Just remove T and
ask yourself how to do it. If you cannot do it without T, then you cannot do
it with T either:
public class SpecialArray {
Object[] createSpecialArray()
{
return (Object[])Array.newInstance(???, 10);
// How to get T?
// You do not pass anything into this method
}
}
Your problem is that arrays in Java know their component type at runtime. If
you do new String[5], the object knows it's an... 阅读全帖
(Class)((ParameterizedType)getClass() .
getGenericSuperclass()).getActualTypeArguments()[0];
but there is some limit on this approach. check with hibernate generic dao
implementation
【 以下文字转载自 JobHunting 讨论区 】
发信人: lwsOsgvd (lwsOsgvd), 信区: JobHunting
标 题: 用c怎么实现generic stack
发信站: BBS 未名空间站 (Tue Apr 24 16:42:43 2012, 美东)
用设计个stack,要求是The stack should be able to take as input a wide
variety of data types: it could range from byte sized to an n-byte sized
structure。
刚好在PIE书里面看到这个
typedef struct Element {
struct Element *next;
void *data;
} Element;
不知道算不算达到要求。
多谢!
DATATYPE can be anything , pointer or a complex data struct.
And there is not cast need in my Code.
Indeed, Type Cast DOES cost overhead. And if constantly doing that, codes
will become bitterly disgusting for debugging by programmers. For example,
the "undefined member" issues will happen alot when programmer forget the
original definition of the data type need to be converted.
Also, you already conclude yourself that "除了多打几个字". If comparing with
easiness of developing, more typing means more m... 阅读全帖
Generic Host Process for Win32 Services has encountered a problem,blah,
blah,....
对于这个老问题了,我都一直忍过来了,每次把弹出的窗口关掉了事。
可是换了64 bit windows xp (x86) 之后,这个问题变得无法容忍了。每次打开my
computer (资源管理器)都需要2分钟以上的时间,然后弹出这个错误信息,然后再
等2分钟,然后my computer才打开了...
有人能救救我吗?
Sorry to bother you. Can any topology expert here help me with the following.
I read the paper:
Decentralized pole assignment and product grassmannians, SIAM journal on
control and optimization, vol. 32, no 3, pp. 855-875, 1994.
I got a paragraph like this:
Let $\Sigma_{m,p}^n$ be the set of all m-input, p-output
systems of degree n. Recall that $\Sigma_{m,p}^n$ is a quasi-affine variety
of dimension $n(m+p)$. A subset $U$ of $\Sigma_{m,p}^n$ is said to be
generic if $U$ is open and dense in $\S