everyone, I'm newbie. My purpose is to get the byte[] buf variable from ByteArrayInputStream by extends it, in this http://www.java2s.com/Open-Source/Android/android-core/platform-libcore/java/io/ByteArrayInputStream.java.htm tells that ByteArrayInputStream has no no-args constructor, but when I code:
class Test extends ByteArrayInputStream {
public Test(int i){}
}
eclipse tells me: Implicit super constructor ByteArrayInputStream() is undefined. Must explicitly invoke another constructor. Before ask this I searched google then got these: Java error: Implicit super constructor is undefined for default constructor , it tells that if class B extends class A, then class A has to define a no-args constructor. OK, this easy for the classes we wrote, but what about classes from Sun's package... I wonder about this too
Thanks in advance.
two concepts to remember:
here, public Test(int i) will call ByteArrayInputStream(), which doesn't exist. So u must call any existing constructor of ByteArrayInputStream in Test(int i)'s 1st statement as like super(required_parameters);
Your Test class should have at least two constructors :
public class Test extends ByteArrayInputStream {
public Test(byte[] buf) {
super(buf);
}
public Test(byte[] buf, int offset, int length) {
super(buf, offset, length);
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.