Hi, I got the following exception when running the codes attached below: Exception in thread "main" java.lang.InstantiationException: IFactory$1 at java.lang.Class.newInstance0(Class.java:281) at java.lang.Class.newInstance(Class.java:249) at IFactory.getI(IFactory.java:20) at IFactory.main(IFactory.java:35) Is it because Java doesn't support reflection for anonymous inner class? If so, how can I have dynamic classes? Is it possible? Thanks in advance. Gary import
i*n
3 楼
in china law is just joke, is bitch.
n*k
4 楼
Does this have anything to do the famous reflection error, you must have a default public constructor, in order to use class.newInstance() method.
【在 c********k 的大作中提到】 : Hi, I got the following exception when running the codes attached below: : Exception in thread "main" java.lang.InstantiationException: IFactory$1 : at java.lang.Class.newInstance0(Class.java:281) : at java.lang.Class.newInstance(Class.java:249) : at IFactory.getI(IFactory.java:20) : at IFactory.main(IFactory.java:35) : Is it because Java doesn't support reflection for anonymous inner class? If : so, how can I have dynamic classes? Is it possible? : Thanks in advance. : Gary
m*s
5 楼
这是闹大 了,对QQ不好,
e*g
6 楼
it does'nt make sense. anonym. inner class needs access to parent object, even local variables, how could it be created outside the scope it is defined. use static public nested class.
【在 c********k 的大作中提到】 : Hi, I got the following exception when running the codes attached below: : Exception in thread "main" java.lang.InstantiationException: IFactory$1 : at java.lang.Class.newInstance0(Class.java:281) : at java.lang.Class.newInstance(Class.java:249) : at IFactory.getI(IFactory.java:20) : at IFactory.main(IFactory.java:35) : Is it because Java doesn't support reflection for anonymous inner class? If : so, how can I have dynamic classes? Is it possible? : Thanks in advance. : Gary
L*3
7 楼
QQ is a free software..
m*t
8 楼
IMO,this problem is caused by that any non-static inner class does not have a default constructor(i.e. an argumentless one). They always have a constructor that takes a reference to the enclosing instance. There is no way you can do the thing you are trying to do in the way you are doing it now. 8-) I think you are doing things in Java with some COM mentality. Dynamic Proxy is probably what you are looking for...
【在 c********k 的大作中提到】 : Hi, I got the following exception when running the codes attached below: : Exception in thread "main" java.lang.InstantiationException: IFactory$1 : at java.lang.Class.newInstance0(Class.java:281) : at java.lang.Class.newInstance(Class.java:249) : at IFactory.getI(IFactory.java:20) : at IFactory.main(IFactory.java:35) : Is it because Java doesn't support reflection for anonymous inner class? If : so, how can I have dynamic classes? Is it possible? : Thanks in advance. : Gary