Skip to content
This repository was archived by the owner on Feb 16, 2022. It is now read-only.

Commit c46bc02

Browse files
author
ParkJeongHwan
committed
Changed allocate algorithm.
1 parent 1e76daf commit c46bc02

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

src/main/java/com/realtimetech/reflection/allocate/UnsafeAllocator.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ public abstract class UnsafeAllocator {
1313
instance = create();
1414
}
1515

16-
public static UnsafeAllocator getInstance() {
17-
return instance;
16+
public static <T> T newInstance(Class<T> c) throws Exception {
17+
return instance.allocate(c);
1818
}
1919

2020
private static UnsafeAllocator create() {
@@ -27,7 +27,7 @@ private static UnsafeAllocator create() {
2727
return new UnsafeAllocator() {
2828
@Override
2929
@SuppressWarnings("unchecked")
30-
public <T> T newInstance(Class<T> c) throws Exception {
30+
public <T> T allocate(Class<T> c) throws Exception {
3131
assertInstantiable(c);
3232
return (T) allocateInstance.invoke(unsafe, c);
3333
}
@@ -44,7 +44,7 @@ public <T> T newInstance(Class<T> c) throws Exception {
4444
return new UnsafeAllocator() {
4545
@Override
4646
@SuppressWarnings("unchecked")
47-
public <T> T newInstance(Class<T> c) throws Exception {
47+
public <T> T allocate(Class<T> c) throws Exception {
4848
assertInstantiable(c);
4949
return (T) newInstance.invoke(null, c, constructorId);
5050
}
@@ -59,7 +59,7 @@ public <T> T newInstance(Class<T> c) throws Exception {
5959
return new UnsafeAllocator() {
6060
@Override
6161
@SuppressWarnings("unchecked")
62-
public <T> T newInstance(Class<T> c) throws Exception {
62+
public <T> T allocate(Class<T> c) throws Exception {
6363
assertInstantiable(c);
6464
return (T) newInstance.invoke(null, c, Object.class);
6565
}
@@ -69,7 +69,7 @@ public <T> T newInstance(Class<T> c) throws Exception {
6969

7070
return new UnsafeAllocator() {
7171
@Override
72-
public <T> T newInstance(Class<T> c) {
72+
public <T> T allocate(Class<T> c) {
7373
throw new UnsupportedOperationException("Cannot allocate " + c);
7474
}
7575
};
@@ -85,5 +85,5 @@ static void assertInstantiable(Class<?> c) {
8585
}
8686
}
8787

88-
public abstract <T> T newInstance(Class<T> c) throws Exception;
88+
public abstract <T> T allocate(Class<T> c) throws Exception;
8989
}

0 commit comments

Comments
 (0)