This topic has been archived. It cannot be replied.
-
工作学习 / 专业知识杂谈 / 有关java inner class的问题,请高手给各解答。I have two class A and B,define like this:
Class A{
...
class C c{
}
B b=new B(this);
...
}
Class B{
B(A a){
}
}
C is inner class of A,C was used by A,the error was issued from line “new B(this),it's said constructor B(A.C) is undefined,I don't want this constructor,I only need B(A a),what can I do?
thanks!
-xiangdang(大魏);
2006-7-15
{326}
(#3081368@0)
-
try B b=new B(A.this)
-markriver(markriver);
2006-7-15
(#3081506@0)
-
class C c{ } 有这样的写法?发回重贴。
-wukongjj(不怕做不到就怕想不到);
2006-7-15
(#3081518@0)
-
而且我觉得他把B b=new B(this)放到了Class C的{} 里了
-markriver(markriver);
2006-7-15
(#3081524@0)
-
对不起,没仔细检查,我改过了Class A{
...
class C{
...
}//end of class C
C c=new C();
B b=new B(this);//error occured here--
...
}//end of class A
Class B{
B(A a){
}
}//end Class B
-xiangdang(大魏);
2006-7-15
{163}
(#3081576@0)
-
where did you put those 2 lines, in a method?
C c=new C();
B b=new B(this);//error occured here--You should redesign your solution!
-maple2000(烈日下的民工);
2006-7-15
{34}
(#3081645@0)
-
Markriver,能否给解释一下。谢了!
-xiangdang(大魏);
2006-7-15
(#3081641@0)
-
谢谢大家,程序已改正!谢谢大家,程序没错,编译能通过,我搞错了,把b=new B(this)放在了A中了,实际上应该在inner class中,所以markriver的解答是对的,在inner class中要用outer class要用OutClassName.this.多谢多谢!
-xiangdang(大魏);
2006-7-15
{182}
(#3082130@0)
-
what's your intention to use inner class C here? what's the reason to cross reference class A and class B? What're the real use cases, more details please.
-maple2000(烈日下的民工);
2006-7-15
(#3081648@0)
-
cut and paste the included code, it shows everything works fine.
-maple2000(烈日下的民工);
2006-7-15
{677}
(#3081670@0)