Topic: 请问,如何access default class ?

  Print this page

1.请问,如何access default class ? Copy to clipboard
Posted by: constantin
Posted on: 2007-09-25 10:12

请问各位大哥, 一个问题,如何从不同包接入default class 呢?
我看到一方法是这样的
package one
class testOne implement Itest {
public testOne(){}

public int getValue( ){return 1;}
}

public interface Itest {
public int getValue();
}

public class testAccessible {
private testAccessible(){}
public static Itest getTestOneDetails(){
return new testOne();
}
}

package two
class testTwo {
public testTwo(){}
public int setValue(){
Itest _itest = testAccessible.getTestOneDetails();
_itest.getValue();
}
}
假设import没有问题。
我的问题是在这个class里,return 是个什么值? 是testOne 的instance 吗 ?
那那个Itest 是做什么用呢?
public static Itest getTestOneDetails(){
return new testOne();
}
谢谢大家解释了。

2.Re:请问,如何access default class ? [Re: constantin] Copy to clipboard
Posted by: andy_wang_5
Posted on: 2007-09-25 11:07

返回的是testOne的instance.
testOne是Itest 的子类。根据上溯造型(upcase)的原理。这样写是没问题的。
upcase是安全的。编译器可以自动完成。不需要强制类型转化。

3.Re:请问,如何access default class ? [Re: constantin] Copy to clipboard
Posted by: andy_wang_5
Posted on: 2007-09-25 11:30

使用Itest 是为了降低程序的耦合度,方便以后扩展。

4.Re:请问,如何access default class ? [Re: constantin] Copy to clipboard
Posted by: JiafanZhou
Posted on: 2007-09-25 16:55

testTwo.setValue() defined as an *int* return type, I haven't seen a return statement in that method, I guess the compiler will also dislike that line and hence fails the compilation process.

Regards,
Jiafan


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923