Refactor Reflection examples
This commit is contained in:
+2
-2
@@ -12,8 +12,8 @@
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.3</version>
|
||||
<configuration>
|
||||
<source>7</source>
|
||||
<target>7</target>
|
||||
<source>8</source>
|
||||
<target>8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
|
||||
@@ -1,25 +1,27 @@
|
||||
package com.baeldung.reflection;
|
||||
|
||||
public abstract class Animal implements Eating{
|
||||
public static final String CATEGORY = "domestic";
|
||||
private String name;
|
||||
public abstract class Animal implements Eating {
|
||||
|
||||
public Animal(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public static final String CATEGORY = "domestic";
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
private String name;
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public Animal(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String makeSound() {
|
||||
return getSound();
|
||||
}
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
protected abstract String getSound();
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String makeSound() {
|
||||
return getSound();
|
||||
}
|
||||
|
||||
protected abstract String getSound();
|
||||
|
||||
}
|
||||
|
||||
@@ -1,33 +1,36 @@
|
||||
package com.baeldung.reflection;
|
||||
|
||||
public class Bird extends Animal {
|
||||
private boolean walks;
|
||||
public Bird() {
|
||||
super("bird");
|
||||
}
|
||||
public Bird(String name, boolean walks) {
|
||||
super(name);
|
||||
setWalks(walks);
|
||||
}
|
||||
public Bird(String name) {
|
||||
super(name);
|
||||
}
|
||||
private boolean walks;
|
||||
|
||||
@Override
|
||||
public String eats() {
|
||||
return "grains";
|
||||
}
|
||||
public Bird() {
|
||||
super("bird");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getSound() {
|
||||
return "chaps";
|
||||
}
|
||||
public Bird(String name, boolean walks) {
|
||||
super(name);
|
||||
setWalks(walks);
|
||||
}
|
||||
|
||||
public boolean walks() {
|
||||
return walks;
|
||||
}
|
||||
public Bird(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
public void setWalks(boolean walks) {
|
||||
this.walks = walks;
|
||||
}
|
||||
@Override
|
||||
public String eats() {
|
||||
return "grains";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getSound() {
|
||||
return "chaps";
|
||||
}
|
||||
|
||||
public boolean walks() {
|
||||
return walks;
|
||||
}
|
||||
|
||||
public void setWalks(boolean walks) {
|
||||
this.walks = walks;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
package com.baeldung.reflection;
|
||||
|
||||
public interface Eating {
|
||||
String eats();
|
||||
String eats();
|
||||
}
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
package com.baeldung.reflection;
|
||||
|
||||
public class Goat extends Animal implements Locomotion{
|
||||
public class Goat extends Animal implements Locomotion {
|
||||
|
||||
public Goat(String name) {
|
||||
super(name);
|
||||
}
|
||||
public Goat(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getSound() {
|
||||
return "bleat";
|
||||
}
|
||||
@Override
|
||||
protected String getSound() {
|
||||
return "bleat";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLocomotion() {
|
||||
return "walks";
|
||||
}
|
||||
@Override
|
||||
public String getLocomotion() {
|
||||
return "walks";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String eats() {
|
||||
return "grass";
|
||||
}
|
||||
@Override
|
||||
public String eats() {
|
||||
return "grass";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
package com.baeldung.reflection;
|
||||
|
||||
public interface Locomotion {
|
||||
String getLocomotion();
|
||||
String getLocomotion();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.baeldung.reflection;
|
||||
|
||||
public class Person {
|
||||
private String name;
|
||||
private int age;
|
||||
private String name;
|
||||
private int age;
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user