Merge pull request #6624 from alv21/BAEL-2426
BAEL-2426 - Cannot reference X before Supertype, exampels
This commit is contained in:
commit
57aa207f85
|
@ -0,0 +1,4 @@
|
|||
target/
|
||||
.idea/
|
||||
bin/
|
||||
*.iml
|
|
@ -0,0 +1,5 @@
|
|||
=========
|
||||
|
||||
## Core Java Lang OOP 2 Cookbooks and Examples
|
||||
|
||||
### Relevant Articles:
|
|
@ -0,0 +1,27 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>core-java-lang-oop-2</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
<name>core-java-lang-oop-2</name>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-java</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../parent-java</relativePath>
|
||||
</parent>
|
||||
|
||||
<build>
|
||||
<finalName>core-java-lang-oop-2</finalName>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,16 @@
|
|||
package com.baeldung.supertypecompilerexception;
|
||||
|
||||
public class MyClass {
|
||||
|
||||
private int myField1 = 10;
|
||||
private int myField2;
|
||||
|
||||
public MyClass() {
|
||||
//uncomment this to see the supertype compiler error:
|
||||
//this(myField1);
|
||||
}
|
||||
|
||||
public MyClass(int i) {
|
||||
myField2 = i;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package com.baeldung.supertypecompilerexception;
|
||||
|
||||
public class MyClassSolution1 {
|
||||
|
||||
private int myField1 = 10;
|
||||
private int myField2;
|
||||
|
||||
public MyClassSolution1() {
|
||||
myField2 = myField1;
|
||||
}
|
||||
|
||||
public MyClassSolution1(int i) {
|
||||
myField2 = i;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package com.baeldung.supertypecompilerexception;
|
||||
|
||||
public class MyClassSolution2 {
|
||||
|
||||
private int myField1 = 10;
|
||||
private int myField2;
|
||||
|
||||
public MyClassSolution2() {
|
||||
setupMyFields(myField1);
|
||||
}
|
||||
|
||||
public MyClassSolution2(int i) {
|
||||
setupMyFields(i);
|
||||
}
|
||||
|
||||
private void setupMyFields(int i) {
|
||||
myField2 = i;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package com.baeldung.supertypecompilerexception;
|
||||
|
||||
public class MyClassSolution3 {
|
||||
|
||||
private static final int SOME_CONSTANT = 10;
|
||||
private int myField2;
|
||||
|
||||
public MyClassSolution3() {
|
||||
this(SOME_CONSTANT);
|
||||
}
|
||||
|
||||
public MyClassSolution3(int i) {
|
||||
myField2 = i;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package com.baeldung.supertypecompilerexception;
|
||||
|
||||
public class MyException extends RuntimeException {
|
||||
private int errorCode = 0;
|
||||
|
||||
public MyException(String message) {
|
||||
//uncomment this to see the supertype compiler error:
|
||||
//super(message + getErrorCode());
|
||||
}
|
||||
|
||||
public int getErrorCode() {
|
||||
return errorCode;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue