Merge pull request #662 from egimaben/master
Java reflection tutorial project
This commit is contained in:
@@ -115,6 +115,9 @@
|
||||
<module>mutation-testing</module>
|
||||
<module>spring-mvc-velocity</module>
|
||||
<module>xstream</module>
|
||||
<module>dozer</module>
|
||||
<module>orika</module>
|
||||
<module>reflection</module>
|
||||
<module>dozer</module>
|
||||
<module>orika</module>
|
||||
</modules>
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
<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/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>reflection</artifactId>
|
||||
<version>1.0</version>
|
||||
<name>reflection</name>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.3</version>
|
||||
<configuration>
|
||||
<source>7</source>
|
||||
<target>7</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.3</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.baeldung.reflection;
|
||||
|
||||
public abstract class Animal implements Eating{
|
||||
public static final String CATEGORY = "domestic";
|
||||
private String name;
|
||||
|
||||
public Animal(String name) {
|
||||
super();
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String makeSound() {
|
||||
return getSound();
|
||||
}
|
||||
|
||||
protected abstract String getSound();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
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);
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.baeldung.reflection;
|
||||
|
||||
public interface Eating {
|
||||
public String eats();
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.baeldung.reflection;
|
||||
|
||||
public class Goat extends Animal implements Locomotion{
|
||||
|
||||
public Goat(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getSound() {
|
||||
return "bleat";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLocomotion() {
|
||||
return "walks";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String eats() {
|
||||
return "grass";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.baeldung.reflection;
|
||||
|
||||
public interface Locomotion {
|
||||
public String getLocomotion();
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package com.baeldung.reflection;
|
||||
|
||||
public class Person {
|
||||
private String name;
|
||||
private int age;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user