【发布时间】:2016-07-03 06:13:51
【问题描述】:
我正在阅读这篇文章:
How do I call one constructor from another in Java?
call one constructor from another in java
但我不知道我的代码有什么问题:
注意:只有我使用三个构造函数的一个调用...错误消息表示为使用// 或/*...*/ 的消息...
class SomeClass {
private RandomAccessFile RAF = null;
public SomeClass(String theName) {
try {
RandomAccessFile raf = new RandomAccessFile(theName, "r");
this(raf); //call to this must be first statement in constructor
SomeClass(raf); /*cannot find symbol
symbol: method SomeClass(RandomAccessFile)
location: class SomeClass*/
this.SomeClass(raf); /*cannot find symbol
symbol: method SomeClass(RandomAccessFile)*/
} catch (IOException e) {}
}
public SomeClass(RandomAccessFile RAFSrc) {
RAF = RAFSrc;
//...
}
//...
}
有什么问题?
【问题讨论】:
标签: java constructor nested constructor-overloading