You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[API Change] Added generics, ClassFinder and Enums
API Change:
The BetterReflectionClass now uses generics to assign a class type
Enums:
Added support for enum classes through the EnumBetterReflectionClass, with the following methods
+ #getEnumConstants()
+ contains(String)
+ getIfPresent(String)
+ getOrNull(String)
+ getOrDefault(String, T)
+ toString(String)
+ toString()
Added a ClassFinder: find and iterate through a java program's classes (both IDE runtime and packed jar)
This class deprecates BetterReflectionUtils#getClassesInPackage(String)
Added unit tests for the ClassFinder class
BetterReflection is a Java library that caches reflection to achieve lower access time.
5
6
6
-
> Note: *BetterReflection is essentially caching reflections. There might be better alternatives for what you are trying to achieve.*
7
+
> Note: *BetterReflection is essentially caching reflections. There might be better alternatives for what you are trying
8
+
to achieve.*
7
9
8
10
#### This library has been created for Java 1.8, results may vary with different Java versions.
9
11
10
12
## Installation
11
-
Every update has been packed into a Jar and released on GitHub. This library is also being hosted on Maven Central, starting with version 1.0
13
+
14
+
Every update has been packed into a Jar and released on GitHub. This library is also being hosted on Maven Central,
15
+
starting with version 1.0
16
+
12
17
```xml
13
18
<dependency>
14
19
<groupId>top.wavelength</groupId>
15
20
<artifactId>Java-BetterReflection</artifactId>
16
21
<version>LATEST_VERSION</version>
17
22
</dependency>
18
23
```
19
-
Note: the package used to be me.wavelength.betterreflection up until version 1.0, where it's been renamed to top.wavelength.betterreflection
24
+
25
+
Note: the package used to be me.wavelength.betterreflection up until version 1.0, where it's been renamed to
26
+
top.wavelength.betterreflection
20
27
21
28
## Usage
22
29
23
-
There are no dependencies needed to use this library. Once you've downloaded it and set it up in your IDE you can start using it.
30
+
There are no dependencies needed to use this library. Once you've downloaded it and set it up in your IDE you can start
31
+
using it.
24
32
25
33
You can temporarily cache a class by simply creating a new instance of BetterReflectionClass
26
34
27
35
```Java
28
-
BetterReflectionClassClassName=newBetterReflectionClass(ClassName.class); // You can also provide a string, containing the package and the name in this format: "com.example.Class".
36
+
BetterReflectionClass<ClassName> className =newBetterReflectionClass<?>(ClassName.class); // You can also provide a string, containing the package and the name in this format: "com.example.Class".
29
37
```
30
38
31
39
## Something more efficient...
32
-
Temporarily caching a class, though, might be worse than using normal reflections, because the BetterReflection class caches everything as soon as instantiated.
33
-
To achieve actually better results than normal reflections you must actually permanently cache said classes.
34
40
41
+
Temporarily caching a class, though, might be worse than using normal reflections, because the BetterReflection class
42
+
caches everything as soon as instantiated.
43
+
To achieve actually better results than normal reflections you must actually permanently cache said classes.
35
44
36
45
### Using the BetterReflection class
37
46
38
47
The BetterReflection class is a class that keeps in an arraylist the cached classes
39
48
40
49
#### Create an instance of BetterReflection inside of your main class
50
+
41
51
```Java
42
52
privateBetterReflection betterReflection;
43
53
@@ -51,19 +61,22 @@ public BetterReflection getBetterReflection() {
51
61
```
52
62
53
63
#### Get the class from the BetterReflection instance you've just created
> Note: *There are some cons to using this method. RAM usage could be somewhat high and once there are many classes looping through a list containing all of them might get expensive*
73
+
> Note: *There are some cons to using this method. RAM usage could be somewhat high and once there are many classes
74
+
looping through a list containing all of them might get expensive*
63
75
64
76
### Alternative way
65
77
66
78
#### Creating a class containing public static final fields
79
+
67
80
```Java
68
81
publicclassListOfMyClasses {
69
82
...
@@ -73,6 +86,7 @@ public class ListOfMyClasses {
73
86
```
74
87
75
88
#### Accessing it from anywhere
89
+
76
90
```Java
77
91
import staticListOfMyClasses.*;
78
92
@@ -98,18 +112,27 @@ public class MyClass {
98
112
There are several ways you can contribute.
99
113
100
114
### Tests
101
-
There are never enough tests! You can create a new test anytime you want to, but your test must meet specific requirements.
115
+
116
+
There are never enough tests! You can create a new test anytime you want to, but your test must meet specific
117
+
requirements.
118
+
102
119
- Your test must extend the Test class
103
120
- Your test must be added to the correct array inside of the Tester class
104
121
- Your test must use the Timer class to return the time passed
105
122
- Your test must tackle somewhat real scenarios
106
123
- Your test must have a good English description
107
124
108
125
### Proper Benchmarks
109
-
If you have some spare time and are generous enough, feel free to implement some proper benchmark and create a pull request. OpenJDK JHM is suggested, but if you're into some other benchmarking libraries feel free to use them instead
126
+
127
+
If you have some spare time and are generous enough, feel free to implement some proper benchmark and create a pull
128
+
request. OpenJDK JHM is suggested, but if you're into some other benchmarking libraries feel free to use them instead
110
129
111
130
### BetterReflection itself
112
-
If you spot issues in the code, think there are better ways to achieve something or think that there are methods that should be added, feel free to add them.
131
+
132
+
If you spot issues in the code, think there are better ways to achieve something or think that there are methods that
133
+
should be added, feel free to add them.
113
134
114
135
### Issues
115
-
Of course, contributing is not limited to code, you can also open issues to report bugs, performance issues or request features.
136
+
137
+
Of course, contributing is not limited to code, you can also open issues to report bugs, performance issues or request
0 commit comments