рдЖрдкрдХрд╛ рджрд┐рди рд╢реБрдн рд╣реЛ!
рдпрд╣ рдкреЛрд╕реНрдЯ рдЙрди рд▓реЛрдЧреЛрдВ рдХреЗ рд▓рд┐рдП рд╣реИ рдЬреЛ рдЬрд╛рд╡рд╛ рднрд╛рд╖рд╛ рдореЗрдВ рдХрд┐рд╕реА рдЕрдиреНрдп рдПрдкреАрдЖрдИ рдкрд░ рдХрд╛рдо рдХрд░ рд░рд╣реЗ рд╣реИрдВ, рдпрд╛ рдХрд┐рд╕реА рдореМрдЬреВрджрд╛ рдХреЛ рдмреЗрд╣рддрд░ рдмрдирд╛рдиреЗ рдХреА рдХреЛрд╢рд┐рд╢ рдХрд░ рд░рд╣реЗ рд╣реИрдВред рд╕рд░рд▓ рд╕рд▓рд╛рд╣ рдпрд╣рд╛рдВ рджреА рдЬрд╛рдПрдЧреА, рдирд┐рд░реНрдорд╛рдг рдХрд╛ рдЙрдкрдпреЛрдЧ рдХреИрд╕реЗ рдХрд░реЗрдВ
? extends T
? extends T
рдФрд░
? super T
рдЖрдкрдХреЗ рдЗрдВрдЯрд░рдлреЗрд╕ рдХреА рдЙрдкрдпреЛрдЧрд┐рддрд╛ рдХреЛ рдмрд╣реБрдд рдмрдврд╝рд╛ рд╕рдХрддреА рд╣реИред
рд╕реАрдзреЗ рдмрд┐рдВрджреБ рдкрд░ рдЬрд╛рдПрдВрд╕реНрд░реЛрдд рдПрдкреАрдЖрдИ
рдорд╛рди рд▓реЗрдВ рдХрд┐ рдЖрдкрдХреЗ рдкрд╛рд╕ рдСрдмреНрдЬреЗрдХреНрдЯреНрд╕ рдХреЗ рдПрдХ рдирд┐рд╢реНрдЪрд┐рдд рд╕реНрдЯреЛрд░реЗрдЬ рдХрд╛ рдЗрдВрдЯрд░рдлрд╝реЗрд╕ рд╣реИ, рдЬреЛ рджреЛ рдкреНрд░рдХрд╛рд░реЛрдВ рд╕реЗ рдкреИрд░рд╛рдореАрдЯрд░рд╛рдЗрдЬрд╝реНрдб, рдХрд╣рддреЗ рд╣реИрдВ: рдХреБрдВрдЬреА рдкреНрд░рдХрд╛рд░ (
K
) рдФрд░ рд╡реИрд▓реНрдпреВ рдЯрд╛рдЗрдк (
V
)ред рдЗрдВрдЯрд░рдлрд╝реЗрд╕ рд░рд┐рдкреЙрдЬрд┐рдЯрд░реА рдореЗрдВ рдбреЗрдЯрд╛ рдХреЗ рд╕рд╛рде рдХрд╛рдо рдХрд░рдиреЗ рдХреЗ рд▓рд┐рдП рдХрдИ рддрд░реАрдХреЛрдВ рдХреЛ рдкрд░рд┐рднрд╛рд╖рд┐рдд рдХрд░рддрд╛ рд╣реИ:
public interface MyObjectStore<K, V> { void put(K key, V value); @Nullable V get(K key); void putAll(Map<K, V> entries); Map<K, V> getAll(Collection<K> keys); Collection<V> getAll(Predicate<V> p); ...
Predicate рдкрд░рд┐рднрд╛рд╖рд╛; interface Predicate<E> { 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
рдХреНрд▓рд╛рд╕ рджреНрд╡рд╛рд░рд╛ рдирд╣реАрдВ, рдмрд▓реНрдХрд┐
Vehicle
рдХреНрд▓рд╛рд╕ рджреНрд╡рд╛рд░рд╛
Vehicle
рдХрд┐рдпрд╛ рдЬрд╛рддрд╛ рд╣реИ, рдЬрд┐рд╕рдореЗрдВ рд╕реЗ
Car
рд╡рд┐рд░рд╛рд╕рдд
Car
рдорд┐рд▓реА рд╣реИред рд╡рд╣ рд░рдЯрдирд╛ рдХрд░рдиреЗ рдХреА рдХреЛрд╢рд┐рд╢ рдХрд░ рд╕рдХрддрд╛ рд╣реИ
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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