Skip to content

Commit 0494c1b

Browse files
committed
Remove generic params from cache methods
It doesn't work to have a generic parameter on the method without also providing that parameter to the method some how (i.e. as a class parameter). So in most cases it makes much more sense to simply accept Objects. In the case of providing a ValueLoader, we can guarantee the return type.
1 parent 1bb8157 commit 0494c1b

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/main/java/org/scijava/cache/CacheService.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ public interface CacheService extends SciJavaService {
4747
* @param key A key.
4848
* @param value A value.
4949
*/
50-
<K, V> void put(K key, V value);
50+
void put(Object key, Object value);
5151

5252
/**
5353
* @param key A key
5454
* @return The cached object, or null if the object is not in the cache.
5555
*/
56-
<K, V> V get(K key);
56+
Object get(Object key);
5757

5858
/**
5959
* @param key A key
@@ -63,5 +63,5 @@ public interface CacheService extends SciJavaService {
6363
* of the value loader.
6464
* @throws ExecutionException
6565
*/
66-
<K, V> V get(K key, Callable<V> valueLoader) throws ExecutionException;
66+
<V> V get(Object key, Callable<V> valueLoader) throws ExecutionException;
6767
}

src/main/java/org/scijava/cache/DefaultCacheService.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,21 +52,21 @@ public class DefaultCacheService extends AbstractService implements
5252
private Map<Object, Object> map;
5353

5454
@Override
55-
public <K, V> void put(final K key, final V value) {
55+
public void put(final Object key, final Object value) {
5656
map.put(key, value);
5757
}
5858

59-
@SuppressWarnings("unchecked")
6059
@Override
61-
public <K, V> V get(final K key) {
62-
return (V) map.get(key);
60+
public Object get(final Object key) {
61+
return map.get(key);
6362
}
6463

64+
@SuppressWarnings("unchecked")
6565
@Override
66-
public <K, V> V get(final K key, final Callable<V> valueLoader)
66+
public <V> V get(final Object key, final Callable<V> valueLoader)
6767
throws ExecutionException
6868
{
69-
return get(key);
69+
return (V)get(key);
7070
}
7171

7272
// -- Service Methods --

0 commit comments

Comments
 (0)