made changes to java reflection (#667)
This commit is contained in:
committed by
Grzegorz Piwowarek
parent
6913a968e5
commit
fc1bb6b7b1
@@ -8,9 +8,7 @@ import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static java.util.stream.Collectors.toList;
|
||||
import java.util.ArrayList;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class ReflectionTest {
|
||||
@@ -24,7 +22,6 @@ public class ReflectionTest {
|
||||
|
||||
assertTrue(Arrays.asList("name", "age")
|
||||
.containsAll(actualFieldNames));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -311,16 +308,19 @@ public class ReflectionTest {
|
||||
|
||||
}
|
||||
|
||||
private static List<String> getMethodNames(Method[] methods) {
|
||||
return Stream.of(methods)
|
||||
.map((Method::getName))
|
||||
.collect(toList());
|
||||
}
|
||||
private static List<String> getFieldNames(Field[] fields) {
|
||||
List<String> fieldNames = new ArrayList<>();
|
||||
for (Field field : fields)
|
||||
fieldNames.add(field.getName());
|
||||
return fieldNames;
|
||||
|
||||
private static List<String> getFieldNames(Field[] fields) {
|
||||
return Stream.of(fields)
|
||||
.map(Field::getName)
|
||||
.collect(toList());
|
||||
}
|
||||
}
|
||||
|
||||
private static List<String> getMethodNames(Method[] methods) {
|
||||
List<String> methodNames = new ArrayList<>();
|
||||
for (Method method : methods)
|
||||
methodNames.add(method.getName());
|
||||
return methodNames;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
<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>8</source>
|
||||
<target>8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.3</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -1,23 +0,0 @@
|
||||
package com.baeldung.reflection;
|
||||
|
||||
public abstract class Animal implements Eating {
|
||||
|
||||
public static final String CATEGORY = "domestic";
|
||||
|
||||
private String name;
|
||||
|
||||
public Animal(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
protected abstract String getSound();
|
||||
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
package com.baeldung.reflection;
|
||||
|
||||
public interface Eating {
|
||||
String eats();
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
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";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
package com.baeldung.reflection;
|
||||
|
||||
public interface Locomotion {
|
||||
String getLocomotion();
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
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