Skip to content

A set of utility methods in addition to the Java Reflection API

License

Notifications You must be signed in to change notification settings

kalaider/reflect4j

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

reflect4j

Build Status codecov

A set of utility methods in addition to the Java Reflection API.

Overview

isOverridden

The package provides a way to check if one method was overridden by another.

class ClassA<T> {
    void test(T arg1, List<? extends T> arg2) {  }
}

class ClassB<T>
    extends ClassA<T> {
    @Override void test(T arg1, List<? extends T> arg2) {  }
}

isOverridden(ClassA.class.getDeclaredMethod("test", Object.class, List.class),
             ClassB.class.getDeclaredMethod("test", Object.class, List.class)));

// output

/*
    true
*/

resolveParameters

Resolves the actual parameter types of a generic class against its superclass, e.i. maps generic parameters of superclass to generic parameters of subclass.

class TestClass1<K, T extends List<K>> {  }

class TestClass2<P>
    extends TestClass1<P, List<P>> {  }

class TestClass3
    extends TestClass2<Number> {  }

System.out.println(
    resolveParameters(TestClass1.class, TestClass2.class));
System.out.println(
    resolveParameters(TestClass1.class, TestClass3.class));
System.out.println(
    resolveParameters(TestClass2.class, TestClass3.class));

// output

/*
    {T=java.util.List<P>, K=P}
    {T=java.util.List<P>, P=class java.lang.Number, K=class java.lang.Number}
    {P=class java.lang.Number}
*/

About

A set of utility methods in addition to the Java Reflection API

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages