? extends T ? extends T and ? super T ? super T can greatly enhance the usability of your interface.K ) and a value type ( V ). The interface defines a set of methods for working with data in the repository: public interface MyObjectStore<K, V> { /** * . * * @param key . * @param value . */ void put(K key, V value); /** * . * * @param key . * @return null. */ @Nullable V get(K key); /** * - . * * @param entries -. */ void putAll(Map<K, V> entries); /** * * . * * @param keys . * @return -. */ Map<K, V> getAll(Collection<K> keys); /** * , * (). * * @param p . * @return , . */ Collection<V> getAll(Predicate<V> p); ... // } interface Predicate<E> { /** * true, * , false . * * @param exp . * @return true, ; false, . */ boolean apply(E exp); } MyObjectStore<Long, Car> carsStore = ...; carsStore.put(20334L, new Car("BMW", "X5", 2013)); Car c = carsStore.get(222L); ... ? super T ? super T Collection<Car> cars = carsStore.getAll(new Predicate<Car>() { @Override public boolean apply(Car exp) { ... // . } }); Car class, but by the Vehicle class, from which Car inherits. He may try to cram Predicate Predicate, :
no suitable method found for getAll(Predicate<Vehicle>)
, , Vehicle - Car . Car , , , Vehicle , Car ! Vehicle Car . , , , :
final Predicate<Vehicle> vp = mgr.getVehiclePredicate(); Collection<Car> cars = carsStore.getAll(new Predicate<Car>() { @Override public boolean apply(Car exp) { return vp.apply(exp); } });
! :
Collection<V> getAll(Predicate<? super V> p);
Predicate<? super V> " V V ( Object)". , . Vehicle :
MyObjectStore<Long, Car> carsStore = ...; Predicate<Vehicle> vp = mgr.getVehiclePredicate(); Collection<Car> cars = carsStore.getAll(vp);
, .
? extends T
, . , , ? extends T . : MyObjectStore<Long, Vehicle> , Map<Long, Car> ( Car - Vehicle ), :
MyObjectStore<Long, Vehicle> carsStore = ...; Map<Long, Car> cars = new HashMap<Long, Car>(2); cars.put(1L, new Car("Audi", "A6", 2011)); cars.put(2L, new Car("Honda", "Civic", 2012)); carsStore.putAll(cars); // .
, , , , wildcard ? extends T :
void putAll(Map<? extends K, ? extends V> entries);
Map<? extends K, ? extends V> " K K V V".
PECS - Producer Extends Consumer Super
, , , .
Joshua Bloch PECS (Producer Extends Consumer Super) , Java Generics and Collections (Maurice Naftalin, Philip Wadler) - Get and Put Principle . PECS, . :
(, Collection Predicate), , - ( producer ), ? extends T , - ( consumer ), ? super T .
, ? : , - , , . , , T.
Predicate - ( getAll(Predicate) T), Map<K, V> - ( putAll(Map<K, V>) T - T K V - ).
, , - , , ( , ) - .
- wildcard- , wildcard- .
PECS-, MyObjectStore , . put(K, V) get(K) (.. ); putAll(Map<? extends K, ? extends V>) getAll(Predicate<? super V>) , ; getAll(Collection) - , .
Map<K, V> getAll(Collection<K> keys);
Map<K, V> getAll(Collection<? extends K> keys);
, API! (, !)
. - :
interface Factory<T> { /** * . * * @param args . * @return . */ T create(Object... args); }
, , , :
interface Cloner<T> { /** * . * * @param obj . * @return . */ T clone(T obj); }
, ouput-, ( Java ).
PECS (Producer Extends Consumer Super) API Java. , , API. , , , PECS , .
Joshua Bloch - Effective Java (2nd Edition) Maurice Naftalin, Philip Wadler - Java Generics and Collections Predicate Predicate, :
no suitable method found for getAll(Predicate<Vehicle>)
, , Vehicle - Car . Car , , , Vehicle , Car ! Vehicle Car . , , , :
final Predicate<Vehicle> vp = mgr.getVehiclePredicate(); Collection<Car> cars = carsStore.getAll(new Predicate<Car>() { @Override public boolean apply(Car exp) { return vp.apply(exp); } });
! :
Collection<V> getAll(Predicate<? super V> p);
Predicate<? super V> " V V ( Object)". , . Vehicle :
MyObjectStore<Long, Car> carsStore = ...; Predicate<Vehicle> vp = mgr.getVehiclePredicate(); Collection<Car> cars = carsStore.getAll(vp);
, .
? extends T
, . , , ? extends T . : MyObjectStore<Long, Vehicle> , Map<Long, Car> ( Car - Vehicle ), :
MyObjectStore<Long, Vehicle> carsStore = ...; Map<Long, Car> cars = new HashMap<Long, Car>(2); cars.put(1L, new Car("Audi", "A6", 2011)); cars.put(2L, new Car("Honda", "Civic", 2012)); carsStore.putAll(cars); // .
, , , , wildcard ? extends T :
void putAll(Map<? extends K, ? extends V> entries);
Map<? extends K, ? extends V> " K K V V".
PECS - Producer Extends Consumer Super
, , , .
Joshua Bloch PECS (Producer Extends Consumer Super) , Java Generics and Collections (Maurice Naftalin, Philip Wadler) - Get and Put Principle . PECS, . :
(, Collection Predicate), , - ( producer ), ? extends T , - ( consumer ), ? super T .
, ? : , - , , . , , T.
Predicate - ( getAll(Predicate) T), Map<K, V> - ( putAll(Map<K, V>) T - T K V - ).
, , - , , ( , ) - .
- wildcard- , wildcard- .
PECS-, MyObjectStore , . put(K, V) get(K) (.. ); putAll(Map<? extends K, ? extends V>) getAll(Predicate<? super V>) , ; getAll(Collection) - , .
Map<K, V> getAll(Collection<K> keys);
Map<K, V> getAll(Collection<? extends K> keys);
, API! (, !)
. - :
interface Factory<T> { /** * . * * @param args . * @return . */ T create(Object... args); }
, , , :
interface Cloner<T> { /** * . * * @param obj . * @return . */ T clone(T obj); }
, ouput-, ( Java ).
PECS (Producer Extends Consumer Super) API Java. , , API. , , , PECS , .
Joshua Bloch - Effective Java (2nd Edition) Maurice Naftalin, Philip Wadler - Java Generics and Collections
Predicate Predicate, :
no suitable method found for getAll(Predicate<Vehicle>)
, , Vehicle - Car . Car , , , Vehicle , Car ! Vehicle Car . , , , :
final Predicate<Vehicle> vp = mgr.getVehiclePredicate(); Collection<Car> cars = carsStore.getAll(new Predicate<Car>() { @Override public boolean apply(Car exp) { return vp.apply(exp); } });
! :
Collection<V> getAll(Predicate<? super V> p);
Predicate<? super V> " V V ( Object)". , . Vehicle :
MyObjectStore<Long, Car> carsStore = ...; Predicate<Vehicle> vp = mgr.getVehiclePredicate(); Collection<Car> cars = carsStore.getAll(vp);
, .
? extends T
, . , , ? extends T . : MyObjectStore<Long, Vehicle> , Map<Long, Car> ( Car - Vehicle ), :
MyObjectStore<Long, Vehicle> carsStore = ...; Map<Long, Car> cars = new HashMap<Long, Car>(2); cars.put(1L, new Car("Audi", "A6", 2011)); cars.put(2L, new Car("Honda", "Civic", 2012)); carsStore.putAll(cars); // .
, , , , wildcard ? extends T :
void putAll(Map<? extends K, ? extends V> entries);
Map<? extends K, ? extends V> " K K V V".
PECS - Producer Extends Consumer Super
, , , .
Joshua Bloch PECS (Producer Extends Consumer Super) , Java Generics and Collections (Maurice Naftalin, Philip Wadler) - Get and Put Principle . PECS, . :
(, Collection Predicate), , - ( producer ), ? extends T , - ( consumer ), ? super T .
, ? : , - , , . , , T.
Predicate - ( getAll(Predicate) T), Map<K, V> - ( putAll(Map<K, V>) T - T K V - ).
, , - , , ( , ) - .
- wildcard- , wildcard- .
PECS-, MyObjectStore , . put(K, V) get(K) (.. ); putAll(Map<? extends K, ? extends V>) getAll(Predicate<? super V>) , ; getAll(Collection) - , .
Map<K, V> getAll(Collection<K> keys);
Map<K, V> getAll(Collection<? extends K> keys);
, API! (, !)
. - :
interface Factory<T> { /** * . * * @param args . * @return . */ T create(Object... args); }
, , , :
interface Cloner<T> { /** * . * * @param obj . * @return . */ T clone(T obj); }
, ouput-, ( Java ).
PECS (Producer Extends Consumer Super) API Java. , , API. , , , PECS , .
Joshua Bloch - Effective Java (2nd Edition) Maurice Naftalin, Philip Wadler - Java Generics and Collections Predicate Predicate, :
no suitable method found for getAll(Predicate<Vehicle>)
, , Vehicle - Car . Car , , , Vehicle , Car ! Vehicle Car . , , , :
final Predicate<Vehicle> vp = mgr.getVehiclePredicate(); Collection<Car> cars = carsStore.getAll(new Predicate<Car>() { @Override public boolean apply(Car exp) { return vp.apply(exp); } });
! :
Collection<V> getAll(Predicate<? super V> p);
Predicate<? super V> " V V ( Object)". , . Vehicle :
MyObjectStore<Long, Car> carsStore = ...; Predicate<Vehicle> vp = mgr.getVehiclePredicate(); Collection<Car> cars = carsStore.getAll(vp);
, .
? extends T
, . , , ? extends T . : MyObjectStore<Long, Vehicle> , Map<Long, Car> ( Car - Vehicle ), :
MyObjectStore<Long, Vehicle> carsStore = ...; Map<Long, Car> cars = new HashMap<Long, Car>(2); cars.put(1L, new Car("Audi", "A6", 2011)); cars.put(2L, new Car("Honda", "Civic", 2012)); carsStore.putAll(cars); // .
, , , , wildcard ? extends T :
void putAll(Map<? extends K, ? extends V> entries);
Map<? extends K, ? extends V> " K K V V".
PECS - Producer Extends Consumer Super
, , , .
Joshua Bloch PECS (Producer Extends Consumer Super) , Java Generics and Collections (Maurice Naftalin, Philip Wadler) - Get and Put Principle . PECS, . :
(, Collection Predicate), , - ( producer ), ? extends T , - ( consumer ), ? super T .
, ? : , - , , . , , T.
Predicate - ( getAll(Predicate) T), Map<K, V> - ( putAll(Map<K, V>) T - T K V - ).
, , - , , ( , ) - .
- wildcard- , wildcard- .
PECS-, MyObjectStore , . put(K, V) get(K) (.. ); putAll(Map<? extends K, ? extends V>) getAll(Predicate<? super V>) , ; getAll(Collection) - , .
Map<K, V> getAll(Collection<K> keys);
Map<K, V> getAll(Collection<? extends K> keys);
, API! (, !)
. - :
interface Factory<T> { /** * . * * @param args . * @return . */ T create(Object... args); }
, , , :
interface Cloner<T> { /** * . * * @param obj . * @return . */ T clone(T obj); }
, ouput-, ( Java ).
PECS (Producer Extends Consumer Super) API Java. , , API. , , , PECS , .
Joshua Bloch - Effective Java (2nd Edition) Maurice Naftalin, Philip Wadler - Java Generics and Collections Predicate Predicate, :
no suitable method found for getAll(Predicate<Vehicle>)
, , Vehicle - Car . Car , , , Vehicle , Car ! Vehicle Car . , , , :
final Predicate<Vehicle> vp = mgr.getVehiclePredicate(); Collection<Car> cars = carsStore.getAll(new Predicate<Car>() { @Override public boolean apply(Car exp) { return vp.apply(exp); } });
! :
Collection<V> getAll(Predicate<? super V> p);
Predicate<? super V> " V V ( Object)". , . Vehicle :
MyObjectStore<Long, Car> carsStore = ...; Predicate<Vehicle> vp = mgr.getVehiclePredicate(); Collection<Car> cars = carsStore.getAll(vp);
, .
? extends T
, . , , ? extends T . : MyObjectStore<Long, Vehicle> , Map<Long, Car> ( Car - Vehicle ), :
MyObjectStore<Long, Vehicle> carsStore = ...; Map<Long, Car> cars = new HashMap<Long, Car>(2); cars.put(1L, new Car("Audi", "A6", 2011)); cars.put(2L, new Car("Honda", "Civic", 2012)); carsStore.putAll(cars); // .
, , , , wildcard ? extends T :
void putAll(Map<? extends K, ? extends V> entries);
Map<? extends K, ? extends V> " K K V V".
PECS - Producer Extends Consumer Super
, , , .
Joshua Bloch PECS (Producer Extends Consumer Super) , Java Generics and Collections (Maurice Naftalin, Philip Wadler) - Get and Put Principle . PECS, . :
(, Collection Predicate), , - ( producer ), ? extends T , - ( consumer ), ? super T .
, ? : , - , , . , , T.
Predicate - ( getAll(Predicate) T), Map<K, V> - ( putAll(Map<K, V>) T - T K V - ).
, , - , , ( , ) - .
- wildcard- , wildcard- .
PECS-, MyObjectStore , . put(K, V) get(K) (.. ); putAll(Map<? extends K, ? extends V>) getAll(Predicate<? super V>) , ; getAll(Collection) - , .
Map<K, V> getAll(Collection<K> keys);
Map<K, V> getAll(Collection<? extends K> keys);
, API! (, !)
. - :
interface Factory<T> { /** * . * * @param args . * @return . */ T create(Object... args); }
, , , :
interface Cloner<T> { /** * . * * @param obj . * @return . */ T clone(T obj); }
, ouput-, ( Java ).
PECS (Producer Extends Consumer Super) API Java. , , API. , , , PECS , .
Joshua Bloch - Effective Java (2nd Edition) Maurice Naftalin, Philip Wadler - Java Generics and Collections Predicate Predicate, :
no suitable method found for getAll(Predicate<Vehicle>)
, , Vehicle - Car . Car , , , Vehicle , Car ! Vehicle Car . , , , :
final Predicate<Vehicle> vp = mgr.getVehiclePredicate(); Collection<Car> cars = carsStore.getAll(new Predicate<Car>() { @Override public boolean apply(Car exp) { return vp.apply(exp); } });
! :
Collection<V> getAll(Predicate<? super V> p);
Predicate<? super V> " V V ( Object)". , . Vehicle :
MyObjectStore<Long, Car> carsStore = ...; Predicate<Vehicle> vp = mgr.getVehiclePredicate(); Collection<Car> cars = carsStore.getAll(vp);
, .
? extends T
, . , , ? extends T . : MyObjectStore<Long, Vehicle> , Map<Long, Car> ( Car - Vehicle ), :
MyObjectStore<Long, Vehicle> carsStore = ...; Map<Long, Car> cars = new HashMap<Long, Car>(2); cars.put(1L, new Car("Audi", "A6", 2011)); cars.put(2L, new Car("Honda", "Civic", 2012)); carsStore.putAll(cars); // .
, , , , wildcard ? extends T :
void putAll(Map<? extends K, ? extends V> entries);
Map<? extends K, ? extends V> " K K V V".
PECS - Producer Extends Consumer Super
, , , .
Joshua Bloch PECS (Producer Extends Consumer Super) , Java Generics and Collections (Maurice Naftalin, Philip Wadler) - Get and Put Principle . PECS, . :
(, Collection Predicate), , - ( producer ), ? extends T , - ( consumer ), ? super T .
, ? : , - , , . , , T.
Predicate - ( getAll(Predicate) T), Map<K, V> - ( putAll(Map<K, V>) T - T K V - ).
, , - , , ( , ) - .
- wildcard- , wildcard- .
PECS-, MyObjectStore , . put(K, V) get(K) (.. ); putAll(Map<? extends K, ? extends V>) getAll(Predicate<? super V>) , ; getAll(Collection) - , .
Map<K, V> getAll(Collection<K> keys);
Map<K, V> getAll(Collection<? extends K> keys);
, API! (, !)
. - :
interface Factory<T> { /** * . * * @param args . * @return . */ T create(Object... args); }
, , , :
interface Cloner<T> { /** * . * * @param obj . * @return . */ T clone(T obj); }
, ouput-, ( Java ).
PECS (Producer Extends Consumer Super) API Java. , , API. , , , PECS , .
Joshua Bloch - Effective Java (2nd Edition) Maurice Naftalin, Philip Wadler - Java Generics and Collections Predicate Predicate, :
no suitable method found for getAll(Predicate<Vehicle>)
, , Vehicle - Car . Car , , , Vehicle , Car ! Vehicle Car . , , , :
final Predicate<Vehicle> vp = mgr.getVehiclePredicate(); Collection<Car> cars = carsStore.getAll(new Predicate<Car>() { @Override public boolean apply(Car exp) { return vp.apply(exp); } });
! :
Collection<V> getAll(Predicate<? super V> p);
Predicate<? super V> " V V ( Object)". , . Vehicle :
MyObjectStore<Long, Car> carsStore = ...; Predicate<Vehicle> vp = mgr.getVehiclePredicate(); Collection<Car> cars = carsStore.getAll(vp);
, .
? extends T
, . , , ? extends T . : MyObjectStore<Long, Vehicle> , Map<Long, Car> ( Car - Vehicle ), :
MyObjectStore<Long, Vehicle> carsStore = ...; Map<Long, Car> cars = new HashMap<Long, Car>(2); cars.put(1L, new Car("Audi", "A6", 2011)); cars.put(2L, new Car("Honda", "Civic", 2012)); carsStore.putAll(cars); // .
, , , , wildcard ? extends T :
void putAll(Map<? extends K, ? extends V> entries);
Map<? extends K, ? extends V> " K K V V".
PECS - Producer Extends Consumer Super
, , , .
Joshua Bloch PECS (Producer Extends Consumer Super) , Java Generics and Collections (Maurice Naftalin, Philip Wadler) - Get and Put Principle . PECS, . :
(, Collection Predicate), , - ( producer ), ? extends T , - ( consumer ), ? super T .
, ? : , - , , . , , T.
Predicate - ( getAll(Predicate) T), Map<K, V> - ( putAll(Map<K, V>) T - T K V - ).
, , - , , ( , ) - .
- wildcard- , wildcard- .
PECS-, MyObjectStore , . put(K, V) get(K) (.. ); putAll(Map<? extends K, ? extends V>) getAll(Predicate<? super V>) , ; getAll(Collection) - , .
Map<K, V> getAll(Collection<K> keys);
Map<K, V> getAll(Collection<? extends K> keys);
, API! (, !)
. - :
interface Factory<T> { /** * . * * @param args . * @return . */ T create(Object... args); }
, , , :
interface Cloner<T> { /** * . * * @param obj . * @return . */ T clone(T obj); }
, ouput-, ( Java ).
PECS (Producer Extends Consumer Super) API Java. , , API. , , , PECS , .
Joshua Bloch - Effective Java (2nd Edition) Maurice Naftalin, Philip Wadler - Java Generics and Collections Predicate Predicate, :
no suitable method found for getAll(Predicate<Vehicle>)
, , Vehicle - Car . Car , , , Vehicle , Car ! Vehicle Car . , , , :
final Predicate<Vehicle> vp = mgr.getVehiclePredicate(); Collection<Car> cars = carsStore.getAll(new Predicate<Car>() { @Override public boolean apply(Car exp) { return vp.apply(exp); } });
! :
Collection<V> getAll(Predicate<? super V> p);
Predicate<? super V> " V V ( Object)". , . Vehicle :
MyObjectStore<Long, Car> carsStore = ...; Predicate<Vehicle> vp = mgr.getVehiclePredicate(); Collection<Car> cars = carsStore.getAll(vp);
, .
? extends T
, . , , ? extends T . : MyObjectStore<Long, Vehicle> , Map<Long, Car> ( Car - Vehicle ), :
MyObjectStore<Long, Vehicle> carsStore = ...; Map<Long, Car> cars = new HashMap<Long, Car>(2); cars.put(1L, new Car("Audi", "A6", 2011)); cars.put(2L, new Car("Honda", "Civic", 2012)); carsStore.putAll(cars); // .
, , , , wildcard ? extends T :
void putAll(Map<? extends K, ? extends V> entries);
Map<? extends K, ? extends V> " K K V V".
PECS - Producer Extends Consumer Super
, , , .
Joshua Bloch PECS (Producer Extends Consumer Super) , Java Generics and Collections (Maurice Naftalin, Philip Wadler) - Get and Put Principle . PECS, . :
(, Collection Predicate), , - ( producer ), ? extends T , - ( consumer ), ? super T .
, ? : , - , , . , , T.
Predicate - ( getAll(Predicate) T), Map<K, V> - ( putAll(Map<K, V>) T - T K V - ).
, , - , , ( , ) - .
- wildcard- , wildcard- .
PECS-, MyObjectStore , . put(K, V) get(K) (.. ); putAll(Map<? extends K, ? extends V>) getAll(Predicate<? super V>) , ; getAll(Collection) - , .
Map<K, V> getAll(Collection<K> keys);
Map<K, V> getAll(Collection<? extends K> keys);
, API! (, !)
. - :
interface Factory<T> { /** * . * * @param args . * @return . */ T create(Object... args); }
, , , :
interface Cloner<T> { /** * . * * @param obj . * @return . */ T clone(T obj); }
, ouput-, ( Java ).
PECS (Producer Extends Consumer Super) API Java. , , API. , , , PECS , .
Joshua Bloch - Effective Java (2nd Edition) Maurice Naftalin, Philip Wadler - Java Generics and Collections Predicate Predicate, :
no suitable method found for getAll(Predicate<Vehicle>)
, , Vehicle - Car . Car , , , Vehicle , Car ! Vehicle Car . , , , :
final Predicate<Vehicle> vp = mgr.getVehiclePredicate(); Collection<Car> cars = carsStore.getAll(new Predicate<Car>() { @Override public boolean apply(Car exp) { return vp.apply(exp); } });
! :
Collection<V> getAll(Predicate<? super V> p);
Predicate<? super V> " V V ( Object)". , . Vehicle :
MyObjectStore<Long, Car> carsStore = ...; Predicate<Vehicle> vp = mgr.getVehiclePredicate(); Collection<Car> cars = carsStore.getAll(vp);
, .
? extends T
, . , , ? extends T . : MyObjectStore<Long, Vehicle> , Map<Long, Car> ( Car - Vehicle ), :
MyObjectStore<Long, Vehicle> carsStore = ...; Map<Long, Car> cars = new HashMap<Long, Car>(2); cars.put(1L, new Car("Audi", "A6", 2011)); cars.put(2L, new Car("Honda", "Civic", 2012)); carsStore.putAll(cars); // .
, , , , wildcard ? extends T :
void putAll(Map<? extends K, ? extends V> entries);
Map<? extends K, ? extends V> " K K V V".
PECS - Producer Extends Consumer Super
, , , .
Joshua Bloch PECS (Producer Extends Consumer Super) , Java Generics and Collections (Maurice Naftalin, Philip Wadler) - Get and Put Principle . PECS, . :
(, Collection Predicate), , - ( producer ), ? extends T , - ( consumer ), ? super T .
, ? : , - , , . , , T.
Predicate - ( getAll(Predicate) T), Map<K, V> - ( putAll(Map<K, V>) T - T K V - ).
, , - , , ( , ) - .
- wildcard- , wildcard- .
PECS-, MyObjectStore , . put(K, V) get(K) (.. ); putAll(Map<? extends K, ? extends V>) getAll(Predicate<? super V>) , ; getAll(Collection) - , .
Map<K, V> getAll(Collection<K> keys);
Map<K, V> getAll(Collection<? extends K> keys);
, API! (, !)
. - :
interface Factory<T> { /** * . * * @param args . * @return . */ T create(Object... args); }
, , , :
interface Cloner<T> { /** * . * * @param obj . * @return . */ T clone(T obj); }
, ouput-, ( Java ).
PECS (Producer Extends Consumer Super) API Java. , , API. , , , PECS , .
Joshua Bloch - Effective Java (2nd Edition) Maurice Naftalin, Philip Wadler - Java Generics and CollectionsPredicate Predicate, :
no suitable method found for getAll(Predicate<Vehicle>)
, , Vehicle - Car . Car , , , Vehicle , Car ! Vehicle Car . , , , :
final Predicate<Vehicle> vp = mgr.getVehiclePredicate(); Collection<Car> cars = carsStore.getAll(new Predicate<Car>() { @Override public boolean apply(Car exp) { return vp.apply(exp); } });
! :
Collection<V> getAll(Predicate<? super V> p);
Predicate<? super V> " V V ( Object)". , . Vehicle :
MyObjectStore<Long, Car> carsStore = ...; Predicate<Vehicle> vp = mgr.getVehiclePredicate(); Collection<Car> cars = carsStore.getAll(vp);
, .
? extends T
, . , , ? extends T . : MyObjectStore<Long, Vehicle> , Map<Long, Car> ( Car - Vehicle ), :
MyObjectStore<Long, Vehicle> carsStore = ...; Map<Long, Car> cars = new HashMap<Long, Car>(2); cars.put(1L, new Car("Audi", "A6", 2011)); cars.put(2L, new Car("Honda", "Civic", 2012)); carsStore.putAll(cars); // .
, , , , wildcard ? extends T :
void putAll(Map<? extends K, ? extends V> entries);
Map<? extends K, ? extends V> " K K V V".
PECS - Producer Extends Consumer Super
, , , .
Joshua Bloch PECS (Producer Extends Consumer Super) , Java Generics and Collections (Maurice Naftalin, Philip Wadler) - Get and Put Principle . PECS, . :
(, Collection Predicate), , - ( producer ), ? extends T , - ( consumer ), ? super T .
, ? : , - , , . , , T.
Predicate - ( getAll(Predicate) T), Map<K, V> - ( putAll(Map<K, V>) T - T K V - ).
, , - , , ( , ) - .
- wildcard- , wildcard- .
PECS-, MyObjectStore , . put(K, V) get(K) (.. ); putAll(Map<? extends K, ? extends V>) getAll(Predicate<? super V>) , ; getAll(Collection) - , .
Map<K, V> getAll(Collection<K> keys);
Map<K, V> getAll(Collection<? extends K> keys);
, API! (, !)
. - :
interface Factory<T> { /** * . * * @param args . * @return . */ T create(Object... args); }
, , , :
interface Cloner<T> { /** * . * * @param obj . * @return . */ T clone(T obj); }
, ouput-, ( Java ).
PECS (Producer Extends Consumer Super) API Java. , , API. , , , PECS , .
Joshua Bloch - Effective Java (2nd Edition) Maurice Naftalin, Philip Wadler - Java Generics and CollectionsPredicate Predicate, :
no suitable method found for getAll(Predicate<Vehicle>)
, , Vehicle - Car . Car , , , Vehicle , Car ! Vehicle Car . , , , :
final Predicate<Vehicle> vp = mgr.getVehiclePredicate(); Collection<Car> cars = carsStore.getAll(new Predicate<Car>() { @Override public boolean apply(Car exp) { return vp.apply(exp); } });
! :
Collection<V> getAll(Predicate<? super V> p);
Predicate<? super V> " V V ( Object)". , . Vehicle :
MyObjectStore<Long, Car> carsStore = ...; Predicate<Vehicle> vp = mgr.getVehiclePredicate(); Collection<Car> cars = carsStore.getAll(vp);
, .
? extends T
, . , , ? extends T . : MyObjectStore<Long, Vehicle> , Map<Long, Car> ( Car - Vehicle ), :
MyObjectStore<Long, Vehicle> carsStore = ...; Map<Long, Car> cars = new HashMap<Long, Car>(2); cars.put(1L, new Car("Audi", "A6", 2011)); cars.put(2L, new Car("Honda", "Civic", 2012)); carsStore.putAll(cars); // .
, , , , wildcard ? extends T :
void putAll(Map<? extends K, ? extends V> entries);
Map<? extends K, ? extends V> " K K V V".
PECS - Producer Extends Consumer Super
, , , .
Joshua Bloch PECS (Producer Extends Consumer Super) , Java Generics and Collections (Maurice Naftalin, Philip Wadler) - Get and Put Principle . PECS, . :
(, Collection Predicate), , - ( producer ), ? extends T , - ( consumer ), ? super T .
, ? : , - , , . , , T.
Predicate - ( getAll(Predicate) T), Map<K, V> - ( putAll(Map<K, V>) T - T K V - ).
, , - , , ( , ) - .
- wildcard- , wildcard- .
PECS-, MyObjectStore , . put(K, V) get(K) (.. ); putAll(Map<? extends K, ? extends V>) getAll(Predicate<? super V>) , ; getAll(Collection) - , .
Map<K, V> getAll(Collection<K> keys);
Map<K, V> getAll(Collection<? extends K> keys);
, API! (, !)
. - :
interface Factory<T> { /** * . * * @param args . * @return . */ T create(Object... args); }
, , , :
interface Cloner<T> { /** * . * * @param obj . * @return . */ T clone(T obj); }
, ouput-, ( Java ).
PECS (Producer Extends Consumer Super) API Java. , , API. , , , PECS , .
Joshua Bloch - Effective Java (2nd Edition) Maurice Naftalin, Philip Wadler - Java Generics and Collections Predicate Predicate, :
no suitable method found for getAll(Predicate<Vehicle>)
, , Vehicle - Car . Car , , , Vehicle , Car ! Vehicle Car . , , , :
final Predicate<Vehicle> vp = mgr.getVehiclePredicate(); Collection<Car> cars = carsStore.getAll(new Predicate<Car>() { @Override public boolean apply(Car exp) { return vp.apply(exp); } });
! :
Collection<V> getAll(Predicate<? super V> p);
Predicate<? super V> " V V ( Object)". , . Vehicle :
MyObjectStore<Long, Car> carsStore = ...; Predicate<Vehicle> vp = mgr.getVehiclePredicate(); Collection<Car> cars = carsStore.getAll(vp);
, .
? extends T
, . , , ? extends T . : MyObjectStore<Long, Vehicle> , Map<Long, Car> ( Car - Vehicle ), :
MyObjectStore<Long, Vehicle> carsStore = ...; Map<Long, Car> cars = new HashMap<Long, Car>(2); cars.put(1L, new Car("Audi", "A6", 2011)); cars.put(2L, new Car("Honda", "Civic", 2012)); carsStore.putAll(cars); // .
, , , , wildcard ? extends T :
void putAll(Map<? extends K, ? extends V> entries);
Map<? extends K, ? extends V> " K K V V".
PECS - Producer Extends Consumer Super
, , , .
Joshua Bloch PECS (Producer Extends Consumer Super) , Java Generics and Collections (Maurice Naftalin, Philip Wadler) - Get and Put Principle . PECS, . :
(, Collection Predicate), , - ( producer ), ? extends T , - ( consumer ), ? super T .
, ? : , - , , . , , T.
Predicate - ( getAll(Predicate) T), Map<K, V> - ( putAll(Map<K, V>) T - T K V - ).
, , - , , ( , ) - .
- wildcard- , wildcard- .
PECS-, MyObjectStore , . put(K, V) get(K) (.. ); putAll(Map<? extends K, ? extends V>) getAll(Predicate<? super V>) , ; getAll(Collection) - , .
Map<K, V> getAll(Collection<K> keys);
Map<K, V> getAll(Collection<? extends K> keys);
, API! (, !)
. - :
interface Factory<T> { /** * . * * @param args . * @return . */ T create(Object... args); }
, , , :
interface Cloner<T> { /** * . * * @param obj . * @return . */ T clone(T obj); }
, ouput-, ( Java ).
PECS (Producer Extends Consumer Super) API Java. , , API. , , , PECS , .
Joshua Bloch - Effective Java (2nd Edition) Maurice Naftalin, Philip Wadler - Java Generics and Collections Predicate Predicate, :
no suitable method found for getAll(Predicate<Vehicle>)
, , Vehicle - Car . Car , , , Vehicle , Car ! Vehicle Car . , , , :
final Predicate<Vehicle> vp = mgr.getVehiclePredicate(); Collection<Car> cars = carsStore.getAll(new Predicate<Car>() { @Override public boolean apply(Car exp) { return vp.apply(exp); } });
! :
Collection<V> getAll(Predicate<? super V> p);
Predicate<? super V> " V V ( Object)". , . Vehicle :
MyObjectStore<Long, Car> carsStore = ...; Predicate<Vehicle> vp = mgr.getVehiclePredicate(); Collection<Car> cars = carsStore.getAll(vp);
, .
? extends T
, . , , ? extends T . : MyObjectStore<Long, Vehicle> , Map<Long, Car> ( Car - Vehicle ), :
MyObjectStore<Long, Vehicle> carsStore = ...; Map<Long, Car> cars = new HashMap<Long, Car>(2); cars.put(1L, new Car("Audi", "A6", 2011)); cars.put(2L, new Car("Honda", "Civic", 2012)); carsStore.putAll(cars); // .
, , , , wildcard ? extends T :
void putAll(Map<? extends K, ? extends V> entries);
Map<? extends K, ? extends V> " K K V V".
PECS - Producer Extends Consumer Super
, , , .
Joshua Bloch PECS (Producer Extends Consumer Super) , Java Generics and Collections (Maurice Naftalin, Philip Wadler) - Get and Put Principle . PECS, . :
(, Collection Predicate), , - ( producer ), ? extends T , - ( consumer ), ? super T .
, ? : , - , , . , , T.
Predicate - ( getAll(Predicate) T), Map<K, V> - ( putAll(Map<K, V>) T - T K V - ).
, , - , , ( , ) - .
- wildcard- , wildcard- .
PECS-, MyObjectStore , . put(K, V) get(K) (.. ); putAll(Map<? extends K, ? extends V>) getAll(Predicate<? super V>) , ; getAll(Collection) - , .
Map<K, V> getAll(Collection<K> keys);
Map<K, V> getAll(Collection<? extends K> keys);
, API! (, !)
. - :
interface Factory<T> { /** * . * * @param args . * @return . */ T create(Object... args); }
, , , :
interface Cloner<T> { /** * . * * @param obj . * @return . */ T clone(T obj); }
, ouput-, ( Java ).
PECS (Producer Extends Consumer Super) API Java. , , API. , , , PECS , .
Joshua Bloch - Effective Java (2nd Edition) Maurice Naftalin, Philip Wadler - Java Generics and Collections Predicate Predicate, :
no suitable method found for getAll(Predicate<Vehicle>)
, , Vehicle - Car . Car , , , Vehicle , Car ! Vehicle Car . , , , :
final Predicate<Vehicle> vp = mgr.getVehiclePredicate(); Collection<Car> cars = carsStore.getAll(new Predicate<Car>() { @Override public boolean apply(Car exp) { return vp.apply(exp); } });
! :
Collection<V> getAll(Predicate<? super V> p);
Predicate<? super V> " V V ( Object)". , . Vehicle :
MyObjectStore<Long, Car> carsStore = ...; Predicate<Vehicle> vp = mgr.getVehiclePredicate(); Collection<Car> cars = carsStore.getAll(vp);
, .
? extends T
, . , , ? extends T . : MyObjectStore<Long, Vehicle> , Map<Long, Car> ( Car - Vehicle ), :
MyObjectStore<Long, Vehicle> carsStore = ...; Map<Long, Car> cars = new HashMap<Long, Car>(2); cars.put(1L, new Car("Audi", "A6", 2011)); cars.put(2L, new Car("Honda", "Civic", 2012)); carsStore.putAll(cars); // .
, , , , wildcard ? extends T :
void putAll(Map<? extends K, ? extends V> entries);
Map<? extends K, ? extends V> " K K V V".
PECS - Producer Extends Consumer Super
, , , .
Joshua Bloch PECS (Producer Extends Consumer Super) , Java Generics and Collections (Maurice Naftalin, Philip Wadler) - Get and Put Principle . PECS, . :
(, Collection Predicate), , - ( producer ), ? extends T , - ( consumer ), ? super T .
, ? : , - , , . , , T.
Predicate - ( getAll(Predicate) T), Map<K, V> - ( putAll(Map<K, V>) T - T K V - ).
, , - , , ( , ) - .
- wildcard- , wildcard- .
PECS-, MyObjectStore , . put(K, V) get(K) (.. ); putAll(Map<? extends K, ? extends V>) getAll(Predicate<? super V>) , ; getAll(Collection) - , .
Map<K, V> getAll(Collection<K> keys);
Map<K, V> getAll(Collection<? extends K> keys);
, API! (, !)
. - :
interface Factory<T> { /** * . * * @param args . * @return . */ T create(Object... args); }
, , , :
interface Cloner<T> { /** * . * * @param obj . * @return . */ T clone(T obj); }
, ouput-, ( Java ).
PECS (Producer Extends Consumer Super) API Java. , , API. , , , PECS , .
Joshua Bloch - Effective Java (2nd Edition) Maurice Naftalin, Philip Wadler - Java Generics and Collections Predicate Predicate, :
no suitable method found for getAll(Predicate<Vehicle>)
, , Vehicle - Car . Car , , , Vehicle , Car ! Vehicle Car . , , , :
final Predicate<Vehicle> vp = mgr.getVehiclePredicate(); Collection<Car> cars = carsStore.getAll(new Predicate<Car>() { @Override public boolean apply(Car exp) { return vp.apply(exp); } });
! :
Collection<V> getAll(Predicate<? super V> p);
Predicate<? super V> " V V ( Object)". , . Vehicle :
MyObjectStore<Long, Car> carsStore = ...; Predicate<Vehicle> vp = mgr.getVehiclePredicate(); Collection<Car> cars = carsStore.getAll(vp);
, .
? extends T
, . , , ? extends T . : MyObjectStore<Long, Vehicle> , Map<Long, Car> ( Car - Vehicle ), :
MyObjectStore<Long, Vehicle> carsStore = ...; Map<Long, Car> cars = new HashMap<Long, Car>(2); cars.put(1L, new Car("Audi", "A6", 2011)); cars.put(2L, new Car("Honda", "Civic", 2012)); carsStore.putAll(cars); // .
, , , , wildcard ? extends T :
void putAll(Map<? extends K, ? extends V> entries);
Map<? extends K, ? extends V> " K K V V".
PECS - Producer Extends Consumer Super
, , , .
Joshua Bloch PECS (Producer Extends Consumer Super) , Java Generics and Collections (Maurice Naftalin, Philip Wadler) - Get and Put Principle . PECS, . :
(, Collection Predicate), , - ( producer ), ? extends T , - ( consumer ), ? super T .
, ? : , - , , . , , T.
Predicate - ( getAll(Predicate) T), Map<K, V> - ( putAll(Map<K, V>) T - T K V - ).
, , - , , ( , ) - .
- wildcard- , wildcard- .
PECS-, MyObjectStore , . put(K, V) get(K) (.. ); putAll(Map<? extends K, ? extends V>) getAll(Predicate<? super V>) , ; getAll(Collection) - , .
Map<K, V> getAll(Collection<K> keys);
Map<K, V> getAll(Collection<? extends K> keys);
, API! (, !)
. - :
interface Factory<T> { /** * . * * @param args . * @return . */ T create(Object... args); }
, , , :
interface Cloner<T> { /** * . * * @param obj . * @return . */ T clone(T obj); }
, ouput-, ( Java ).
PECS (Producer Extends Consumer Super) API Java. , , API. , , , PECS , .
Joshua Bloch - Effective Java (2nd Edition) Maurice Naftalin, Philip Wadler - Java Generics and CollectionsPredicate Predicate, :
no suitable method found for getAll(Predicate<Vehicle>)
, , Vehicle - Car . Car , , , Vehicle , Car ! Vehicle Car . , , , :
final Predicate<Vehicle> vp = mgr.getVehiclePredicate(); Collection<Car> cars = carsStore.getAll(new Predicate<Car>() { @Override public boolean apply(Car exp) { return vp.apply(exp); } });
! :
Collection<V> getAll(Predicate<? super V> p);
Predicate<? super V> " V V ( Object)". , . Vehicle :
MyObjectStore<Long, Car> carsStore = ...; Predicate<Vehicle> vp = mgr.getVehiclePredicate(); Collection<Car> cars = carsStore.getAll(vp);
, .
? extends T
, . , , ? extends T . : MyObjectStore<Long, Vehicle> , Map<Long, Car> ( Car - Vehicle ), :
MyObjectStore<Long, Vehicle> carsStore = ...; Map<Long, Car> cars = new HashMap<Long, Car>(2); cars.put(1L, new Car("Audi", "A6", 2011)); cars.put(2L, new Car("Honda", "Civic", 2012)); carsStore.putAll(cars); // .
, , , , wildcard ? extends T :
void putAll(Map<? extends K, ? extends V> entries);
Map<? extends K, ? extends V> " K K V V".
PECS - Producer Extends Consumer Super
, , , .
Joshua Bloch PECS (Producer Extends Consumer Super) , Java Generics and Collections (Maurice Naftalin, Philip Wadler) - Get and Put Principle . PECS, . :
(, Collection Predicate), , - ( producer ), ? extends T , - ( consumer ), ? super T .
, ? : , - , , . , , T.
Predicate - ( getAll(Predicate) T), Map<K, V> - ( putAll(Map<K, V>) T - T K V - ).
, , - , , ( , ) - .
- wildcard- , wildcard- .
PECS-, MyObjectStore , . put(K, V) get(K) (.. ); putAll(Map<? extends K, ? extends V>) getAll(Predicate<? super V>) , ; getAll(Collection) - , .
Map<K, V> getAll(Collection<K> keys);
Map<K, V> getAll(Collection<? extends K> keys);
, API! (, !)
. - :
interface Factory<T> { /** * . * * @param args . * @return . */ T create(Object... args); }
, , , :
interface Cloner<T> { /** * . * * @param obj . * @return . */ T clone(T obj); }
, ouput-, ( Java ).
PECS (Producer Extends Consumer Super) API Java. , , API. , , , PECS , .
Joshua Bloch - Effective Java (2nd Edition) Maurice Naftalin, Philip Wadler - Java Generics and CollectionsPredicate Predicate, :
no suitable method found for getAll(Predicate<Vehicle>)
, , Vehicle - Car . Car , , , Vehicle , Car ! Vehicle Car . , , , :
final Predicate<Vehicle> vp = mgr.getVehiclePredicate(); Collection<Car> cars = carsStore.getAll(new Predicate<Car>() { @Override public boolean apply(Car exp) { return vp.apply(exp); } });
! :
Collection<V> getAll(Predicate<? super V> p);
Predicate<? super V> " V V ( Object)". , . Vehicle :
MyObjectStore<Long, Car> carsStore = ...; Predicate<Vehicle> vp = mgr.getVehiclePredicate(); Collection<Car> cars = carsStore.getAll(vp);
, .
? extends T
, . , , ? extends T . : MyObjectStore<Long, Vehicle> , Map<Long, Car> ( Car - Vehicle ), :
MyObjectStore<Long, Vehicle> carsStore = ...; Map<Long, Car> cars = new HashMap<Long, Car>(2); cars.put(1L, new Car("Audi", "A6", 2011)); cars.put(2L, new Car("Honda", "Civic", 2012)); carsStore.putAll(cars); // .
, , , , wildcard ? extends T :
void putAll(Map<? extends K, ? extends V> entries);
Map<? extends K, ? extends V> " K K V V".
PECS - Producer Extends Consumer Super
, , , .
Joshua Bloch PECS (Producer Extends Consumer Super) , Java Generics and Collections (Maurice Naftalin, Philip Wadler) - Get and Put Principle . PECS, . :
(, Collection Predicate), , - ( producer ), ? extends T , - ( consumer ), ? super T .
, ? : , - , , . , , T.
Predicate - ( getAll(Predicate) T), Map<K, V> - ( putAll(Map<K, V>) T - T K V - ).
, , - , , ( , ) - .
- wildcard- , wildcard- .
PECS-, MyObjectStore , . put(K, V) get(K) (.. ); putAll(Map<? extends K, ? extends V>) getAll(Predicate<? super V>) , ; getAll(Collection) - , .
Map<K, V> getAll(Collection<K> keys);
Map<K, V> getAll(Collection<? extends K> keys);
, API! (, !)
. - :
interface Factory<T> { /** * . * * @param args . * @return . */ T create(Object... args); }
, , , :
interface Cloner<T> { /** * . * * @param obj . * @return . */ T clone(T obj); }
, ouput-, ( Java ).
PECS (Producer Extends Consumer Super) API Java. , , API. , , , PECS , .
Joshua Bloch - Effective Java (2nd Edition) Maurice Naftalin, Philip Wadler - Java Generics and CollectionsPredicate Predicate, :
no suitable method found for getAll(Predicate<Vehicle>)
, ,Vehicle-Car.Car, , ,Vehicle,Car!VehicleCar. , , , :final Predicate<Vehicle> vp = mgr.getVehiclePredicate(); Collection<Car> cars = carsStore.getAll(new Predicate<Car>() { @Override public boolean apply(Car exp) { return vp.apply(exp); } });
! :Collection<V> getAll(Predicate<? super V> p);Predicate<? super V>" V V ( Object)". , .Vehicle:MyObjectStore<Long, Car> carsStore = ...; Predicate<Vehicle> vp = mgr.getVehiclePredicate(); Collection<Car> cars = carsStore.getAll(vp);
, .? extends T
, . , ,? extends T. :MyObjectStore<Long, Vehicle>,Map<Long, Car>(Car-Vehicle), :MyObjectStore<Long, Vehicle> carsStore = ...; Map<Long, Car> cars = new HashMap<Long, Car>(2); cars.put(1L, new Car("Audi", "A6", 2011)); cars.put(2L, new Car("Honda", "Civic", 2012)); carsStore.putAll(cars); // .
, , , , wildcard? extends T:void putAll(Map<? extends K, ? extends V> entries);Map<? extends K, ? extends V>" K K V V".
PECS - Producer Extends Consumer Super
, , , .
Joshua Bloch PECS (Producer Extends Consumer Super) , Java Generics and Collections (Maurice Naftalin, Philip Wadler) - Get and Put Principle . PECS, . :
(,Collection Predicate), , - ( producer ), ? extends T, - ( consumer ),? super T.
, ? : , - , , . , , T.Predicate - ( getAll(Predicate) T), Map<K, V>- ( putAll(Map<K, V>) T - T K V - ).
, , - , , ( , ) - .
- wildcard- , wildcard- .
PECS-,MyObjectStore, .put(K, V)get(K)(.. );putAll(Map<? extends K, ? extends V>)getAll(Predicate<? super V>), ;getAll(Collection) - , .
Map<K, V> getAll(Collection<K> keys);Map<K, V> getAll(Collection<? extends K> keys);
, API! (, !)
. - :interface Factory<T> { /** * . * * @param args . * @return . */ T create(Object... args); }
, , , :interface Cloner<T> { /** * . * * @param obj . * @return . */ T clone(T obj); }
, ouput-, ( Java ).
PECS (Producer Extends Consumer Super) API Java. , , API. , , , PECS , .
Joshua Bloch - Effective Java (2nd Edition) Maurice Naftalin, Philip Wadler - Java Generics and CollectionsgetAll(Collection) - , .Predicate Predicate, :
no suitable method found for getAll(Predicate<Vehicle>)
, ,Vehicle-Car.Car, , ,Vehicle,Car!VehicleCar. , , , :
final Predicate<Vehicle> vp = mgr.getVehiclePredicate(); Collection<Car> cars = carsStore.getAll(new Predicate<Car>() { @Override public boolean apply(Car exp) { return vp.apply(exp); } });
! :
Collection<V> getAll(Predicate<? super V> p);
Predicate<? super V>" V V ( Object)". , .Vehicle:
MyObjectStore<Long, Car> carsStore = ...; Predicate<Vehicle> vp = mgr.getVehiclePredicate(); Collection<Car> cars = carsStore.getAll(vp);
, .
? extends T
, . , ,? extends T. :MyObjectStore<Long, Vehicle>,Map<Long, Car>(Car-Vehicle), :
MyObjectStore<Long, Vehicle> carsStore = ...; Map<Long, Car> cars = new HashMap<Long, Car>(2); cars.put(1L, new Car("Audi", "A6", 2011)); cars.put(2L, new Car("Honda", "Civic", 2012)); carsStore.putAll(cars); // .
, , , , wildcard? extends T:
void putAll(Map<? extends K, ? extends V> entries);
Map<? extends K, ? extends V>" K K V V".
PECS - Producer Extends Consumer Super
, , , .
Joshua Bloch PECS (Producer Extends Consumer Super) , Java Generics and Collections (Maurice Naftalin, Philip Wadler) - Get and Put Principle . PECS, . :
(,Collection Predicate), , - ( producer ), ? extends T, - ( consumer ),? super T.
, ? : , - , , . , , T.
Predicate - ( getAll(Predicate) T), Map<K, V>- ( putAll(Map<K, V>) T - T K V - ).
, , - , , ( , ) - .
- wildcard- , wildcard- .
PECS-,MyObjectStore, .put(K, V)get(K)(.. );putAll(Map<? extends K, ? extends V>)getAll(Predicate<? super V>), ;
Map<K, V> getAll(Collection<K> keys);
Map<K, V> getAll(Collection<? extends K> keys);
, API! (, !)
. - :
interface Factory<T> { /** * . * * @param args . * @return . */ T create(Object... args); }
, , , :
interface Cloner<T> { /** * . * * @param obj . * @return . */ T clone(T obj); }
, ouput-, ( Java ).
PECS (Producer Extends Consumer Super) API Java. , , API. , , , PECS , .
Joshua Bloch - Effective Java (2nd Edition) Maurice Naftalin, Philip Wadler - Java Generics and CollectionsPredicate Predicate, :
no suitable method found for getAll(Predicate<Vehicle>)
, ,Vehicle-Car.Car, , ,Vehicle,Car!VehicleCar. , , , :final Predicate<Vehicle> vp = mgr.getVehiclePredicate(); Collection<Car> cars = carsStore.getAll(new Predicate<Car>() { @Override public boolean apply(Car exp) { return vp.apply(exp); } });
! :Collection<V> getAll(Predicate<? super V> p);Predicate<? super V>" V V ( Object)". , .Vehicle:MyObjectStore<Long, Car> carsStore = ...; Predicate<Vehicle> vp = mgr.getVehiclePredicate(); Collection<Car> cars = carsStore.getAll(vp);
, .? extends T
, . , ,? extends T. :MyObjectStore<Long, Vehicle>,Map<Long, Car>(Car-Vehicle), :MyObjectStore<Long, Vehicle> carsStore = ...; Map<Long, Car> cars = new HashMap<Long, Car>(2); cars.put(1L, new Car("Audi", "A6", 2011)); cars.put(2L, new Car("Honda", "Civic", 2012)); carsStore.putAll(cars); // .
, , , , wildcard? extends T:void putAll(Map<? extends K, ? extends V> entries);Map<? extends K, ? extends V>" K K V V".
PECS - Producer Extends Consumer Super
, , , .
Joshua Bloch PECS (Producer Extends Consumer Super) , Java Generics and Collections (Maurice Naftalin, Philip Wadler) - Get and Put Principle . PECS, . :
(,Collection Predicate), , - ( producer ), ? extends T, - ( consumer ),? super T.
, ? : , - , , . , , T.Predicate - ( getAll(Predicate) T), Map<K, V>- ( putAll(Map<K, V>) T - T K V - ).
, , - , , ( , ) - .
- wildcard- , wildcard- .
PECS-,MyObjectStore, .put(K, V)get(K)(.. );putAll(Map<? extends K, ? extends V>)getAll(Predicate<? super V>), ;getAll(Collection) - , .
Map<K, V> getAll(Collection<K> keys);Map<K, V> getAll(Collection<? extends K> keys);
, API! (, !)
. - :interface Factory<T> { /** * . * * @param args . * @return . */ T create(Object... args); }
, , , :interface Cloner<T> { /** * . * * @param obj . * @return . */ T clone(T obj); }
, ouput-, ( Java ).
PECS (Producer Extends Consumer Super) API Java. , , API. , , , PECS , .
Joshua Bloch - Effective Java (2nd Edition) Maurice Naftalin, Philip Wadler - Java Generics and CollectionsPredicate Predicate, :
no suitable method found for getAll(Predicate<Vehicle>)
, ,Vehicle-Car.Car, , ,Vehicle,Car!VehicleCar. , , , :
final Predicate<Vehicle> vp = mgr.getVehiclePredicate(); Collection<Car> cars = carsStore.getAll(new Predicate<Car>() { @Override public boolean apply(Car exp) { return vp.apply(exp); } });
! :
Collection<V> getAll(Predicate<? super V> p);
Predicate<? super V>" V V ( Object)". , .Vehicle:
MyObjectStore<Long, Car> carsStore = ...; Predicate<Vehicle> vp = mgr.getVehiclePredicate(); Collection<Car> cars = carsStore.getAll(vp);
, .
? extends T
, . , ,? extends T. :MyObjectStore<Long, Vehicle>,Map<Long, Car>(Car-Vehicle), :
MyObjectStore<Long, Vehicle> carsStore = ...; Map<Long, Car> cars = new HashMap<Long, Car>(2); cars.put(1L, new Car("Audi", "A6", 2011)); cars.put(2L, new Car("Honda", "Civic", 2012)); carsStore.putAll(cars); // .
, , , , wildcard? extends T:
void putAll(Map<? extends K, ? extends V> entries);
Map<? extends K, ? extends V>" K K V V".
PECS - Producer Extends Consumer Super
, , , .
Joshua Bloch PECS (Producer Extends Consumer Super) , Java Generics and Collections (Maurice Naftalin, Philip Wadler) - Get and Put Principle . PECS, . :
(,Collection Predicate), , - ( producer ), ? extends T, - ( consumer ),? super T.
, ? : , - , , . , , T.
Predicate - ( getAll(Predicate) T), Map<K, V>- ( putAll(Map<K, V>) T - T K V - ).
, , - , , ( , ) - .
- wildcard- , wildcard- .
PECS-,MyObjectStore, .put(K, V)get(K)(.. );putAll(Map<? extends K, ? extends V>)getAll(Predicate<? super V>), ;getAll(Collection) - , .
Map<K, V> getAll(Collection<K> keys);
Map<K, V> getAll(Collection<? extends K> keys);
, API! (, !)
. - :
interface Factory<T> { /** * . * * @param args . * @return . */ T create(Object... args); }
, , , :
interface Cloner<T> { /** * . * * @param obj . * @return . */ T clone(T obj); }
, ouput-, ( Java ).
PECS (Producer Extends Consumer Super) API Java. , , API. , , , PECS , .
Joshua Bloch - Effective Java (2nd Edition) Maurice Naftalin, Philip Wadler - Java Generics and CollectionsPredicate Predicate, :
no suitable method found for getAll(Predicate<Vehicle>)
, ,Vehicle-Car.Car, , ,Vehicle,Car!VehicleCar. , , , :final Predicate<Vehicle> vp = mgr.getVehiclePredicate(); Collection<Car> cars = carsStore.getAll(new Predicate<Car>() { @Override public boolean apply(Car exp) { return vp.apply(exp); } });
! :Collection<V> getAll(Predicate<? super V> p);Predicate<? super V>" V V ( Object)". , .Vehicle:MyObjectStore<Long, Car> carsStore = ...; Predicate<Vehicle> vp = mgr.getVehiclePredicate(); Collection<Car> cars = carsStore.getAll(vp);
, .? extends T
, . , ,? extends T. :MyObjectStore<Long, Vehicle>,Map<Long, Car>(Car-Vehicle), :MyObjectStore<Long, Vehicle> carsStore = ...; Map<Long, Car> cars = new HashMap<Long, Car>(2); cars.put(1L, new Car("Audi", "A6", 2011)); cars.put(2L, new Car("Honda", "Civic", 2012)); carsStore.putAll(cars); // .
, , , , wildcard? extends T:void putAll(Map<? extends K, ? extends V> entries);Map<? extends K, ? extends V>" K K V V".
PECS - Producer Extends Consumer Super
, , , .
Joshua Bloch PECS (Producer Extends Consumer Super) , Java Generics and Collections (Maurice Naftalin, Philip Wadler) - Get and Put Principle . PECS, . :
(,Collection Predicate), , - ( producer ), ? extends T, - ( consumer ),? super T.
, ? : , - , , . , , T.Predicate - ( getAll(Predicate) T), Map<K, V>- ( putAll(Map<K, V>) T - T K V - ).
, , - , , ( , ) - .
- wildcard- , wildcard- .
PECS-,MyObjectStore, .put(K, V)get(K)(.. );putAll(Map<? extends K, ? extends V>)getAll(Predicate<? super V>), ;getAll(Collection) - , .
Map<K, V> getAll(Collection<K> keys);Map<K, V> getAll(Collection<? extends K> keys);
, API! (, !)
. - :interface Factory<T> { /** * . * * @param args . * @return . */ T create(Object... args); }
, , , :interface Cloner<T> { /** * . * * @param obj . * @return . */ T clone(T obj); }
, ouput-, ( Java ).
PECS (Producer Extends Consumer Super) API Java. , , API. , , , PECS , .
Joshua Bloch - Effective Java (2nd Edition) Maurice Naftalin, Philip Wadler - Java Generics and Collections
Predicate Predicate, :
no suitable method found for getAll(Predicate<Vehicle>)
, ,Vehicle-Car.Car, , ,Vehicle,Car!VehicleCar. , , , :final Predicate<Vehicle> vp = mgr.getVehiclePredicate(); Collection<Car> cars = carsStore.getAll(new Predicate<Car>() { @Override public boolean apply(Car exp) { return vp.apply(exp); } });
! :Collection<V> getAll(Predicate<? super V> p);Predicate<? super V>" V V ( Object)". , .Vehicle:MyObjectStore<Long, Car> carsStore = ...; Predicate<Vehicle> vp = mgr.getVehiclePredicate(); Collection<Car> cars = carsStore.getAll(vp);
, .? extends T
, . , ,? extends T. :MyObjectStore<Long, Vehicle>,Map<Long, Car>(Car-Vehicle), :MyObjectStore<Long, Vehicle> carsStore = ...; Map<Long, Car> cars = new HashMap<Long, Car>(2); cars.put(1L, new Car("Audi", "A6", 2011)); cars.put(2L, new Car("Honda", "Civic", 2012)); carsStore.putAll(cars); // .
, , , , wildcard? extends T:void putAll(Map<? extends K, ? extends V> entries);Map<? extends K, ? extends V>" K K V V".
PECS - Producer Extends Consumer Super
, , , .
Joshua Bloch PECS (Producer Extends Consumer Super) , Java Generics and Collections (Maurice Naftalin, Philip Wadler) - Get and Put Principle . PECS, . :
(,Collection Predicate), , - ( producer ), ? extends T, - ( consumer ),? super T.
, ? : , - , , . , , T.Predicate - ( getAll(Predicate) T), Map<K, V>- ( putAll(Map<K, V>) T - T K V - ).
, , - , , ( , ) - .
- wildcard- , wildcard- .
PECS-,MyObjectStore, .put(K, V)get(K)(.. );putAll(Map<? extends K, ? extends V>)getAll(Predicate<? super V>), ;getAll(Collection) - , .
Map<K, V> getAll(Collection<K> keys);Map<K, V> getAll(Collection<? extends K> keys);
, API! (, !)
. - :interface Factory<T> { /** * . * * @param args . * @return . */ T create(Object... args); }
, , , :interface Cloner<T> { /** * . * * @param obj . * @return . */ T clone(T obj); }
, ouput-, ( Java ).
PECS (Producer Extends Consumer Super) API Java. , , API. , , , PECS , .
Joshua Bloch - Effective Java (2nd Edition) Maurice Naftalin, Philip Wadler - Java Generics and CollectionsPredicate Predicate, :
no suitable method found for getAll(Predicate<Vehicle>)
, ,Vehicle-Car.Car, , ,Vehicle,Car!VehicleCar. , , , :final Predicate<Vehicle> vp = mgr.getVehiclePredicate(); Collection<Car> cars = carsStore.getAll(new Predicate<Car>() { @Override public boolean apply(Car exp) { return vp.apply(exp); } });
! :Collection<V> getAll(Predicate<? super V> p);Predicate<? super V>" V V ( Object)". , .Vehicle:MyObjectStore<Long, Car> carsStore = ...; Predicate<Vehicle> vp = mgr.getVehiclePredicate(); Collection<Car> cars = carsStore.getAll(vp);
, .? extends T
, . , ,? extends T. :MyObjectStore<Long, Vehicle>,Map<Long, Car>(Car-Vehicle), :MyObjectStore<Long, Vehicle> carsStore = ...; Map<Long, Car> cars = new HashMap<Long, Car>(2); cars.put(1L, new Car("Audi", "A6", 2011)); cars.put(2L, new Car("Honda", "Civic", 2012)); carsStore.putAll(cars); // .
, , , , wildcard? extends T:void putAll(Map<? extends K, ? extends V> entries);Map<? extends K, ? extends V>" K K V V".
PECS - Producer Extends Consumer Super
, , , .
Joshua Bloch PECS (Producer Extends Consumer Super) , Java Generics and Collections (Maurice Naftalin, Philip Wadler) - Get and Put Principle . PECS, . :
(,Collection Predicate), , - ( producer ), ? extends T, - ( consumer ),? super T.
, ? : , - , , . , , T.Predicate - ( getAll(Predicate) T), Map<K, V>- ( putAll(Map<K, V>) T - T K V - ).
, , - , , ( , ) - .
- wildcard- , wildcard- .
PECS-,MyObjectStore, .put(K, V)get(K)(.. );putAll(Map<? extends K, ? extends V>)getAll(Predicate<? super V>), ;getAll(Collection) - , .
Map<K, V> getAll(Collection<K> keys);Map<K, V> getAll(Collection<? extends K> keys);
, API! (, !)
. - :interface Factory<T> { /** * . * * @param args . * @return . */ T create(Object... args); }
, , , :interface Cloner<T> { /** * . * * @param obj . * @return . */ T clone(T obj); }
, ouput-, ( Java ).
PECS (Producer Extends Consumer Super) API Java. , , API. , , , PECS , .
Joshua Bloch - Effective Java (2nd Edition) Maurice Naftalin, Philip Wadler - Java Generics and CollectionsPredicate Predicate, :
no suitable method found for getAll(Predicate<Vehicle>)
, ,Vehicle-Car.Car, , ,Vehicle,Car!VehicleCar. , , , :
final Predicate<Vehicle> vp = mgr.getVehiclePredicate(); Collection<Car> cars = carsStore.getAll(new Predicate<Car>() { @Override public boolean apply(Car exp) { return vp.apply(exp); } });
! :
Collection<V> getAll(Predicate<? super V> p);
Predicate<? super V>" V V ( Object)". , .Vehicle:
MyObjectStore<Long, Car> carsStore = ...; Predicate<Vehicle> vp = mgr.getVehiclePredicate(); Collection<Car> cars = carsStore.getAll(vp);
, .
? extends T
, . , ,? extends T. :MyObjectStore<Long, Vehicle>,Map<Long, Car>(Car-Vehicle), :
MyObjectStore<Long, Vehicle> carsStore = ...; Map<Long, Car> cars = new HashMap<Long, Car>(2); cars.put(1L, new Car("Audi", "A6", 2011)); cars.put(2L, new Car("Honda", "Civic", 2012)); carsStore.putAll(cars); // .
, , , , wildcard? extends T:
void putAll(Map<? extends K, ? extends V> entries);
Map<? extends K, ? extends V>" K K V V".
PECS - Producer Extends Consumer Super
, , , .
Joshua Bloch PECS (Producer Extends Consumer Super) , Java Generics and Collections (Maurice Naftalin, Philip Wadler) - Get and Put Principle . PECS, . :
(,Collection Predicate), , - ( producer ), ? extends T, - ( consumer ),? super T.
, ? : , - , , . , , T.
Predicate - ( getAll(Predicate) T), Map<K, V>- ( putAll(Map<K, V>) T - T K V - ).
, , - , , ( , ) - .
- wildcard- , wildcard- .
PECS-,MyObjectStore, .put(K, V)get(K)(.. );putAll(Map<? extends K, ? extends V>)getAll(Predicate<? super V>), ;getAll(Collection) - , .
Map<K, V> getAll(Collection<K> keys);
Map<K, V> getAll(Collection<? extends K> keys);
, API! (, !)
. - :
interface Factory<T> { /** * . * * @param args . * @return . */ T create(Object... args); }
, , , :
interface Cloner<T> { /** * . * * @param obj . * @return . */ T clone(T obj); }
, ouput-, ( Java ).
PECS (Producer Extends Consumer Super) API Java. , , API. , , , PECS , .
Joshua Bloch - Effective Java (2nd Edition) Maurice Naftalin, Philip Wadler - Java Generics and CollectionsPredicate Predicate, :
no suitable method found for getAll(Predicate<Vehicle>)
, ,Vehicle-Car.Car, , ,Vehicle,Car!VehicleCar. , , , :final Predicate<Vehicle> vp = mgr.getVehiclePredicate(); Collection<Car> cars = carsStore.getAll(new Predicate<Car>() { @Override public boolean apply(Car exp) { return vp.apply(exp); } });
! :Collection<V> getAll(Predicate<? super V> p);Predicate<? super V>" V V ( Object)". , .Vehicle:MyObjectStore<Long, Car> carsStore = ...; Predicate<Vehicle> vp = mgr.getVehiclePredicate(); Collection<Car> cars = carsStore.getAll(vp);
, .? extends T
, . , ,? extends T. :MyObjectStore<Long, Vehicle>,Map<Long, Car>(Car-Vehicle), :MyObjectStore<Long, Vehicle> carsStore = ...; Map<Long, Car> cars = new HashMap<Long, Car>(2); cars.put(1L, new Car("Audi", "A6", 2011)); cars.put(2L, new Car("Honda", "Civic", 2012)); carsStore.putAll(cars); // .
, , , , wildcard? extends T:void putAll(Map<? extends K, ? extends V> entries);Map<? extends K, ? extends V>" K K V V".
PECS - Producer Extends Consumer Super
, , , .
Joshua Bloch PECS (Producer Extends Consumer Super) , Java Generics and Collections (Maurice Naftalin, Philip Wadler) - Get and Put Principle . PECS, . :
(,Collection Predicate), , - ( producer ), ? extends T, - ( consumer ),? super T.
, ? : , - , , . , , T.Predicate - ( getAll(Predicate) T), Map<K, V>- ( putAll(Map<K, V>) T - T K V - ).
, , - , , ( , ) - .
- wildcard- , wildcard- .
PECS-,MyObjectStore, .put(K, V)get(K)(.. );putAll(Map<? extends K, ? extends V>)getAll(Predicate<? super V>), ;getAll(Collection) - , .
Map<K, V> getAll(Collection<K> keys);Map<K, V> getAll(Collection<? extends K> keys);
, API! (, !)
. - :interface Factory<T> { /** * . * * @param args . * @return . */ T create(Object... args); }
, , , :interface Cloner<T> { /** * . * * @param obj . * @return . */ T clone(T obj); }
, ouput-, ( Java ).
PECS (Producer Extends Consumer Super) API Java. , , API. , , , PECS , .
Joshua Bloch - Effective Java (2nd Edition) Maurice Naftalin, Philip Wadler - Java Generics and CollectionsPredicate Predicate, :
no suitable method found for getAll(Predicate<Vehicle>)
, ,Vehicle-Car.Car, , ,Vehicle,Car!VehicleCar. , , , :
final Predicate<Vehicle> vp = mgr.getVehiclePredicate(); Collection<Car> cars = carsStore.getAll(new Predicate<Car>() { @Override public boolean apply(Car exp) { return vp.apply(exp); } });
! :
Collection<V> getAll(Predicate<? super V> p);
Predicate<? super V>" V V ( Object)". , .Vehicle:
MyObjectStore<Long, Car> carsStore = ...; Predicate<Vehicle> vp = mgr.getVehiclePredicate(); Collection<Car> cars = carsStore.getAll(vp);
, .
? extends T
, . , ,? extends T. :MyObjectStore<Long, Vehicle>,Map<Long, Car>(Car-Vehicle), :
MyObjectStore<Long, Vehicle> carsStore = ...; Map<Long, Car> cars = new HashMap<Long, Car>(2); cars.put(1L, new Car("Audi", "A6", 2011)); cars.put(2L, new Car("Honda", "Civic", 2012)); carsStore.putAll(cars); // .
, , , , wildcard? extends T:
void putAll(Map<? extends K, ? extends V> entries);
Map<? extends K, ? extends V>" K K V V".
PECS - Producer Extends Consumer Super
, , , .
Joshua Bloch PECS (Producer Extends Consumer Super) , Java Generics and Collections (Maurice Naftalin, Philip Wadler) - Get and Put Principle . PECS, . :
(,Collection Predicate), , - ( producer ), ? extends T, - ( consumer ),? super T.
, ? : , - , , . , , T.
Predicate - ( getAll(Predicate) T), Map<K, V>- ( putAll(Map<K, V>) T - T K V - ).
, , - , , ( , ) - .
- wildcard- , wildcard- .
PECS-,MyObjectStore, .put(K, V)get(K)(.. );putAll(Map<? extends K, ? extends V>)getAll(Predicate<? super V>), ;getAll(Collection) - , .
Map<K, V> getAll(Collection<K> keys);
Map<K, V> getAll(Collection<? extends K> keys);
, API! (, !)
. - :
interface Factory<T> { /** * . * * @param args . * @return . */ T create(Object... args); }
, , , :
interface Cloner<T> { /** * . * * @param obj . * @return . */ T clone(T obj); }
, ouput-, ( Java ).
PECS (Producer Extends Consumer Super) API Java. , , API. , , , PECS , .
Joshua Bloch - Effective Java (2nd Edition) Maurice Naftalin, Philip Wadler - Java Generics and CollectionsPredicate Predicate, :
no suitable method found for getAll(Predicate<Vehicle>)
, ,Vehicle-Car.Car, , ,Vehicle,Car!VehicleCar. , , , :final Predicate<Vehicle> vp = mgr.getVehiclePredicate(); Collection<Car> cars = carsStore.getAll(new Predicate<Car>() { @Override public boolean apply(Car exp) { return vp.apply(exp); } });
! :Collection<V> getAll(Predicate<? super V> p);Predicate<? super V>" V V ( Object)". , .Vehicle:MyObjectStore<Long, Car> carsStore = ...; Predicate<Vehicle> vp = mgr.getVehiclePredicate(); Collection<Car> cars = carsStore.getAll(vp);
, .? extends T
, . , ,? extends T. :MyObjectStore<Long, Vehicle>,Map<Long, Car>(Car-Vehicle), :MyObjectStore<Long, Vehicle> carsStore = ...; Map<Long, Car> cars = new HashMap<Long, Car>(2); cars.put(1L, new Car("Audi", "A6", 2011)); cars.put(2L, new Car("Honda", "Civic", 2012)); carsStore.putAll(cars); // .
, , , , wildcard? extends T:void putAll(Map<? extends K, ? extends V> entries);Map<? extends K, ? extends V>" K K V V".
PECS - Producer Extends Consumer Super
, , , .
Joshua Bloch PECS (Producer Extends Consumer Super) , Java Generics and Collections (Maurice Naftalin, Philip Wadler) - Get and Put Principle . PECS, . :
(,Collection Predicate), , - ( producer ), ? extends T, - ( consumer ),? super T.
, ? : , - , , . , , T.Predicate - ( getAll(Predicate) T), Map<K, V>- ( putAll(Map<K, V>) T - T K V - ).
, , - , , ( , ) - .
- wildcard- , wildcard- .
PECS-,MyObjectStore, .put(K, V)get(K)(.. );putAll(Map<? extends K, ? extends V>)getAll(Predicate<? super V>), ;getAll(Collection) - , .
Map<K, V> getAll(Collection<K> keys);Map<K, V> getAll(Collection<? extends K> keys);
, API! (, !)
. - :interface Factory<T> { /** * . * * @param args . * @return . */ T create(Object... args); }
, , , :interface Cloner<T> { /** * . * * @param obj . * @return . */ T clone(T obj); }
, ouput-, ( Java ).
PECS (Producer Extends Consumer Super) API Java. , , API. , , , PECS , .
Joshua Bloch - Effective Java (2nd Edition) Maurice Naftalin, Philip Wadler - Java Generics and Collections
Predicate Predicate, :
no suitable method found for getAll(Predicate<Vehicle>)
, ,Vehicle-Car.Car, , ,Vehicle,Car!VehicleCar. , , , :final Predicate<Vehicle> vp = mgr.getVehiclePredicate(); Collection<Car> cars = carsStore.getAll(new Predicate<Car>() { @Override public boolean apply(Car exp) { return vp.apply(exp); } });
! :Collection<V> getAll(Predicate<? super V> p);Predicate<? super V>" V V ( Object)". , .Vehicle:MyObjectStore<Long, Car> carsStore = ...; Predicate<Vehicle> vp = mgr.getVehiclePredicate(); Collection<Car> cars = carsStore.getAll(vp);
, .? extends T
, . , ,? extends T. :MyObjectStore<Long, Vehicle>,Map<Long, Car>(Car-Vehicle), :MyObjectStore<Long, Vehicle> carsStore = ...; Map<Long, Car> cars = new HashMap<Long, Car>(2); cars.put(1L, new Car("Audi", "A6", 2011)); cars.put(2L, new Car("Honda", "Civic", 2012)); carsStore.putAll(cars); // .
, , , , wildcard? extends T:void putAll(Map<? extends K, ? extends V> entries);Map<? extends K, ? extends V>" K K V V".
PECS - Producer Extends Consumer Super
, , , .
Joshua Bloch PECS (Producer Extends Consumer Super) , Java Generics and Collections (Maurice Naftalin, Philip Wadler) - Get and Put Principle . PECS, . :
(,Collection Predicate), , - ( producer ), ? extends T, - ( consumer ),? super T.
, ? : , - , , . , , T.Predicate - ( getAll(Predicate) T), Map<K, V>- ( putAll(Map<K, V>) T - T K V - ).
, , - , , ( , ) - .
- wildcard- , wildcard- .
PECS-,MyObjectStore, .put(K, V)get(K)(.. );putAll(Map<? extends K, ? extends V>)getAll(Predicate<? super V>), ;getAll(Collection) - , .
Map<K, V> getAll(Collection<K> keys);Map<K, V> getAll(Collection<? extends K> keys);
, API! (, !)
. - :interface Factory<T> { /** * . * * @param args . * @return . */ T create(Object... args); }
, , , :interface Cloner<T> { /** * . * * @param obj . * @return . */ T clone(T obj); }
, ouput-, ( Java ).
PECS (Producer Extends Consumer Super) API Java. , , API. , , , PECS , .
Joshua Bloch - Effective Java (2nd Edition) Maurice Naftalin, Philip Wadler - Java Generics and CollectionsPredicate Predicate, :
no suitable method found for getAll(Predicate<Vehicle>)
, ,Vehicle-Car.Car, , ,Vehicle,Car!VehicleCar. , , , :final Predicate<Vehicle> vp = mgr.getVehiclePredicate(); Collection<Car> cars = carsStore.getAll(new Predicate<Car>() { @Override public boolean apply(Car exp) { return vp.apply(exp); } });
! :Collection<V> getAll(Predicate<? super V> p);Predicate<? super V>" V V ( Object)". , .Vehicle:MyObjectStore<Long, Car> carsStore = ...; Predicate<Vehicle> vp = mgr.getVehiclePredicate(); Collection<Car> cars = carsStore.getAll(vp);
, .? extends T
, . , ,? extends T. :MyObjectStore<Long, Vehicle>,Map<Long, Car>(Car-Vehicle), :MyObjectStore<Long, Vehicle> carsStore = ...; Map<Long, Car> cars = new HashMap<Long, Car>(2); cars.put(1L, new Car("Audi", "A6", 2011)); cars.put(2L, new Car("Honda", "Civic", 2012)); carsStore.putAll(cars); // .
, , , , wildcard? extends T:void putAll(Map<? extends K, ? extends V> entries);Map<? extends K, ? extends V>" K K V V".
PECS - Producer Extends Consumer Super
, , , .
Joshua Bloch PECS (Producer Extends Consumer Super) , Java Generics and Collections (Maurice Naftalin, Philip Wadler) - Get and Put Principle . PECS, . :
(,Collection Predicate), , - ( producer ), ? extends T, - ( consumer ),? super T.
, ? : , - , , . , , T.Predicate - ( getAll(Predicate) T), Map<K, V>- ( putAll(Map<K, V>) T - T K V - ).
, , - , , ( , ) - .
- wildcard- , wildcard- .
PECS-,MyObjectStore, .put(K, V)get(K)(.. );putAll(Map<? extends K, ? extends V>)getAll(Predicate<? super V>), ;getAll(Collection) - , .
Map<K, V> getAll(Collection<K> keys);Map<K, V> getAll(Collection<? extends K> keys);
, API! (, !)
. - :interface Factory<T> { /** * . * * @param args . * @return . */ T create(Object... args); }
, , , :interface Cloner<T> { /** * . * * @param obj . * @return . */ T clone(T obj); }
, ouput-, ( Java ).
PECS (Producer Extends Consumer Super) API Java. , , API. , , , PECS , .
Joshua Bloch - Effective Java (2nd Edition) Maurice Naftalin, Philip Wadler - Java Generics and Collections
Predicate Predicate, :
no suitable method found for getAll(Predicate<Vehicle>)
, ,Vehicle-Car.Car, , ,Vehicle,Car!VehicleCar. , , , :final Predicate<Vehicle> vp = mgr.getVehiclePredicate(); Collection<Car> cars = carsStore.getAll(new Predicate<Car>() { @Override public boolean apply(Car exp) { return vp.apply(exp); } });
! :Collection<V> getAll(Predicate<? super V> p);Predicate<? super V>" V V ( Object)". , .Vehicle:MyObjectStore<Long, Car> carsStore = ...; Predicate<Vehicle> vp = mgr.getVehiclePredicate(); Collection<Car> cars = carsStore.getAll(vp);
, .? extends T
, . , ,? extends T. :MyObjectStore<Long, Vehicle>,Map<Long, Car>(Car-Vehicle), :MyObjectStore<Long, Vehicle> carsStore = ...; Map<Long, Car> cars = new HashMap<Long, Car>(2); cars.put(1L, new Car("Audi", "A6", 2011)); cars.put(2L, new Car("Honda", "Civic", 2012)); carsStore.putAll(cars); // .
, , , , wildcard? extends T:void putAll(Map<? extends K, ? extends V> entries);Map<? extends K, ? extends V>" K K V V".
PECS - Producer Extends Consumer Super
, , , .
Joshua Bloch PECS (Producer Extends Consumer Super) , Java Generics and Collections (Maurice Naftalin, Philip Wadler) - Get and Put Principle . PECS, . :
(,Collection Predicate), , - ( producer ), ? extends T, - ( consumer ),? super T.
, ? : , - , , . , , T.Predicate - ( getAll(Predicate) T), Map<K, V>- ( putAll(Map<K, V>) T - T K V - ).
, , - , , ( , ) - .
- wildcard- , wildcard- .
PECS-,MyObjectStore, .put(K, V)get(K)(.. );putAll(Map<? extends K, ? extends V>)getAll(Predicate<? super V>), ;getAll(Collection) - , .
Map<K, V> getAll(Collection<K> keys);Map<K, V> getAll(Collection<? extends K> keys);
, API! (, !)
. - :interface Factory<T> { /** * . * * @param args . * @return . */ T create(Object... args); }
, , , :interface Cloner<T> { /** * . * * @param obj . * @return . */ T clone(T obj); }
, ouput-, ( Java ).
PECS (Producer Extends Consumer Super) API Java. , , API. , , , PECS , .
Joshua Bloch - Effective Java (2nd Edition) Maurice Naftalin, Philip Wadler - Java Generics and CollectionsPredicate Predicate, :
no suitable method found for getAll(Predicate<Vehicle>)
, ,Vehicle-Car.Car, , ,Vehicle,Car!VehicleCar. , , , :final Predicate<Vehicle> vp = mgr.getVehiclePredicate(); Collection<Car> cars = carsStore.getAll(new Predicate<Car>() { @Override public boolean apply(Car exp) { return vp.apply(exp); } });
! :Collection<V> getAll(Predicate<? super V> p);Predicate<? super V>" V V ( Object)". , .Vehicle:MyObjectStore<Long, Car> carsStore = ...; Predicate<Vehicle> vp = mgr.getVehiclePredicate(); Collection<Car> cars = carsStore.getAll(vp);
, .? extends T
, . , ,? extends T. :MyObjectStore<Long, Vehicle>,Map<Long, Car>(Car-Vehicle), :MyObjectStore<Long, Vehicle> carsStore = ...; Map<Long, Car> cars = new HashMap<Long, Car>(2); cars.put(1L, new Car("Audi", "A6", 2011)); cars.put(2L, new Car("Honda", "Civic", 2012)); carsStore.putAll(cars); // .
, , , , wildcard? extends T:void putAll(Map<? extends K, ? extends V> entries);Map<? extends K, ? extends V>" K K V V".
PECS - Producer Extends Consumer Super
, , , .
Joshua Bloch PECS (Producer Extends Consumer Super) , Java Generics and Collections (Maurice Naftalin, Philip Wadler) - Get and Put Principle . PECS, . :
(,Collection Predicate), , - ( producer ), ? extends T, - ( consumer ),? super T.
, ? : , - , , . , , T.Predicate - ( getAll(Predicate) T), Map<K, V>- ( putAll(Map<K, V>) T - T K V - ).
, , - , , ( , ) - .
- wildcard- , wildcard- .
PECS-,MyObjectStore, .put(K, V)get(K)(.. );putAll(Map<? extends K, ? extends V>)getAll(Predicate<? super V>), ;getAll(Collection) - , .
Map<K, V> getAll(Collection<K> keys);Map<K, V> getAll(Collection<? extends K> keys);
, API! (, !)
. - :interface Factory<T> { /** * . * * @param args . * @return . */ T create(Object... args); }
, , , :interface Cloner<T> { /** * . * * @param obj . * @return . */ T clone(T obj); }
, ouput-, ( Java ).
PECS (Producer Extends Consumer Super) API Java. , , API. , , , PECS , .
Joshua Bloch - Effective Java (2nd Edition) Maurice Naftalin, Philip Wadler - Java Generics and Collections
Predicate Predicate, :
no suitable method found for getAll(Predicate<Vehicle>)
, ,Vehicle-Car.Car, , ,Vehicle,Car!VehicleCar. , , , :final Predicate<Vehicle> vp = mgr.getVehiclePredicate(); Collection<Car> cars = carsStore.getAll(new Predicate<Car>() { @Override public boolean apply(Car exp) { return vp.apply(exp); } });
! :Collection<V> getAll(Predicate<? super V> p);Predicate<? super V>" V V ( Object)". , .Vehicle:MyObjectStore<Long, Car> carsStore = ...; Predicate<Vehicle> vp = mgr.getVehiclePredicate(); Collection<Car> cars = carsStore.getAll(vp);
, .? extends T
, . , ,? extends T. :MyObjectStore<Long, Vehicle>,Map<Long, Car>(Car-Vehicle), :MyObjectStore<Long, Vehicle> carsStore = ...; Map<Long, Car> cars = new HashMap<Long, Car>(2); cars.put(1L, new Car("Audi", "A6", 2011)); cars.put(2L, new Car("Honda", "Civic", 2012)); carsStore.putAll(cars); // .
, , , , wildcard? extends T:void putAll(Map<? extends K, ? extends V> entries);Map<? extends K, ? extends V>" K K V V".
PECS - Producer Extends Consumer Super
, , , .
Joshua Bloch PECS (Producer Extends Consumer Super) , Java Generics and Collections (Maurice Naftalin, Philip Wadler) - Get and Put Principle . PECS, . :
(,Collection Predicate), , - ( producer ), ? extends T, - ( consumer ),? super T.
, ? : , - , , . , , T.Predicate - ( getAll(Predicate) T), Map<K, V>- ( putAll(Map<K, V>) T - T K V - ).
, , - , , ( , ) - .
- wildcard- , wildcard- .
PECS-,MyObjectStore, .put(K, V)get(K)(.. );putAll(Map<? extends K, ? extends V>)getAll(Predicate<? super V>), ;getAll(Collection) - , .
Map<K, V> getAll(Collection<K> keys);Map<K, V> getAll(Collection<? extends K> keys);
, API! (, !)
. - :interface Factory<T> { /** * . * * @param args . * @return . */ T create(Object... args); }
, , , :interface Cloner<T> { /** * . * * @param obj . * @return . */ T clone(T obj); }
, ouput-, ( Java ).
PECS (Producer Extends Consumer Super) API Java. , , API. , , , PECS , .
Joshua Bloch - Effective Java (2nd Edition) Maurice Naftalin, Philip Wadler - Java Generics and CollectionsPredicate Predicate, :
no suitable method found for getAll(Predicate<Vehicle>)
, ,Vehicle-Car.Car, , ,Vehicle,Car!VehicleCar. , , , :final Predicate<Vehicle> vp = mgr.getVehiclePredicate(); Collection<Car> cars = carsStore.getAll(new Predicate<Car>() { @Override public boolean apply(Car exp) { return vp.apply(exp); } });
! :Collection<V> getAll(Predicate<? super V> p);Predicate<? super V>" V V ( Object)". , .Vehicle:MyObjectStore<Long, Car> carsStore = ...; Predicate<Vehicle> vp = mgr.getVehiclePredicate(); Collection<Car> cars = carsStore.getAll(vp);
, .? extends T
, . , ,? extends T. :MyObjectStore<Long, Vehicle>,Map<Long, Car>(Car-Vehicle), :MyObjectStore<Long, Vehicle> carsStore = ...; Map<Long, Car> cars = new HashMap<Long, Car>(2); cars.put(1L, new Car("Audi", "A6", 2011)); cars.put(2L, new Car("Honda", "Civic", 2012)); carsStore.putAll(cars); // .
, , , , wildcard? extends T:void putAll(Map<? extends K, ? extends V> entries);Map<? extends K, ? extends V>" K K V V".
PECS - Producer Extends Consumer Super
, , , .
Joshua Bloch PECS (Producer Extends Consumer Super) , Java Generics and Collections (Maurice Naftalin, Philip Wadler) - Get and Put Principle . PECS, . :
(,Collection Predicate), , - ( producer ), ? extends T, - ( consumer ),? super T.
, ? : , - , , . , , T.Predicate - ( getAll(Predicate) T), Map<K, V>- ( putAll(Map<K, V>) T - T K V - ).
, , - , , ( , ) - .
- wildcard- , wildcard- .
PECS-,MyObjectStore, .put(K, V)get(K)(.. );putAll(Map<? extends K, ? extends V>)getAll(Predicate<? super V>), ;getAll(Collection) - , .
Map<K, V> getAll(Collection<K> keys);Map<K, V> getAll(Collection<? extends K> keys);
, API! (, !)
. - :interface Factory<T> { /** * . * * @param args . * @return . */ T create(Object... args); }
, , , :interface Cloner<T> { /** * . * * @param obj . * @return . */ T clone(T obj); }
, ouput-, ( Java ).
PECS (Producer Extends Consumer Super) API Java. , , API. , , , PECS , .
Joshua Bloch - Effective Java (2nd Edition) Maurice Naftalin, Philip Wadler - Java Generics and Collections
Source: https://habr.com/ru/post/207360/
All Articles