API Java 11 e versioni successive disponibili mediante il deprovisioning con specifiche minime

Android Studio include il supporto per l'utilizzo di una serie di API Java 11 e versioni successive senza richiedere un livello API minimo per la tua app. Ciò significa che se utilizzi un'API introdotta in Android 13 (livello API 33) il codice funziona anche su tutte le versioni precedenti. La maggior parte delle API introdotte in Android nel corso degli anni è supportata su Android 13. Attraverso una procedura chiamata desugaring delle API, lo strumento di compilazione DEX (D8) consente di includere API di linguaggio più standard in app che supportano versioni precedenti di Android.

Il ritiro dell'API di supporto Java 11 è disponibile in tre versioni:

  • La versione minima include solo il pacchetto java.util.function e le classi di sostituzione per alcune raccolte simultanee di framework Android che presentano problemi noti sui dispositivi precedenti.
  • La versione predefinita è effettivamente una versione aggiornata dell'API Java 8 che ha eseguito il deprovisioning dell'API Java 11. Include i pacchetti java.time e java.util.stream oltre a tutto ciò che è disponibile nella versione minima.
  • La versione nio include il pacchetto java.nio oltre a tutti i contenuti della versione predefinita.

La seguente tabella disponibile per la ricerca mostra quali librerie Java 11 e versioni successive sono disponibili quando utilizzi la versione più recente del plug-in Android per Gradle con la dipendenza coreLibraryDesugaring impostata su com.android.tools:desugar_jdk_libs_minimal:2.0.1 (per ulteriori informazioni, consulta la pagina relativa al desugaring delle API). Imposta questa proprietà nel file build.gradle o build.gradle.kts.

Pacchetto +
Classe,
Enum
o interfaccia
Costruttori,
Proprietà
e metodi
Note
java.util.concurrent


 ConcurrentHashMap.
 KeySetView


  • public boolean add(Object e)
  • public boolean addAll(Collection c)
  • public boolean contains(Object o)
  • public boolean equals(Object o)
  • public void forEach(Consumer action)
  • public Object getMappedValue()
  • public int hashCode()
  • public Iterator iterator()
  • public boolean remove(Object o)
  • public Spliterator spliterator()

Alcuni metodi (8) presenti in Android T non sono supportati.

java.util.concurrent


 ConcurrentHashMap


  • public ConcurrentHashMap()
  • public ConcurrentHashMap(int initialCapacity)
  • public ConcurrentHashMap(
     int initialCapacity, float loadFactor)
  • public ConcurrentHashMap(
      int initialCapacity,
      float loadFactor,
      int concurrencyLevel)
  • public ConcurrentHashMap(Map m)
  • public void clear()
  • public Object compute(
     Object key, BiFunction remappingFunction)
  • public Object computeIfAbsent(
     Object key, Function mappingFunction)
  • public Object computeIfPresent(
     Object key, BiFunction remappingFunction)
  • public boolean contains(Object value)
  • public boolean containsKey(Object key)
  • public boolean containsValue(Object value)
  • public Enumeration elements()
  • public Set entrySet()
  • public boolean equals(Object o)
  • public void forEach(
     long parallelismThreshold, BiConsumer action)
  • public void forEach(
      long parallelismThreshold,
      BiFunction transformer,
      Consumer action)
  • public void forEach(BiConsumer action)
  • public void forEachEntry(
     long parallelismThreshold, Consumer action)
  • public void forEachEntry(
      long parallelismThreshold,
      Function transformer,
      Consumer action)
  • public void forEachKey(
     long parallelismThreshold, Consumer action)
  • public void forEachKey(
      long parallelismThreshold,
      Function transformer,
      Consumer action)
  • public void forEachValue(
     long parallelismThreshold, Consumer action)
  • public void forEachValue(
      long parallelismThreshold,
      Function transformer,
      Consumer action)
  • public Object get(Object key)
  • public Object getOrDefault(
     Object key, Object defaultValue)
  • public int hashCode()
  • public boolean isEmpty()
  • public Set keySet()
  • public ConcurrentHashMap.KeySetView keySet(
     Object mappedValue)
  • public Enumeration keys()
  • public long mappingCount()
  • public Object merge(
      Object key,
      Object value,
      BiFunction remappingFunction)
  • public static ConcurrentHashMap.KeySetView newKeySet()
  • public static ConcurrentHashMap.KeySetView newKeySet(
     int initialCapacity)
  • public Object put(Object key, Object value)
  • public void putAll(Map m)
  • public Object putIfAbsent(Object key, Object value)
  • public Object reduce(
      long parallelismThreshold,
      BiFunction transformer,
      BiFunction reducer)
  • public Object reduceEntries(
      long parallelismThreshold,
      Function transformer,
      BiFunction reducer)
  • public Map.Entry reduceEntries(
     long parallelismThreshold, BiFunction reducer)
  • public double reduceEntriesToDouble(
      long parallelismThreshold,
      ToDoubleFunction transformer,
      double basis,
      DoubleBinaryOperator reducer)
  • public int reduceEntriesToInt(
      long parallelismThreshold,
      ToIntFunction transformer,
      int basis,
      IntBinaryOperator reducer)
  • public long reduceEntriesToLong(
      long parallelismThreshold,
      ToLongFunction transformer,
      long basis,
      LongBinaryOperator reducer)
  • public Object reduceKeys(
     long parallelismThreshold, BiFunction reducer)
  • public Object reduceKeys(
      long parallelismThreshold,
      Function transformer,
      BiFunction reducer)
  • public double reduceKeysToDouble(
      long parallelismThreshold,
      ToDoubleFunction transformer,
      double basis,
      DoubleBinaryOperator reducer)
  • public int reduceKeysToInt(
      long parallelismThreshold,
      ToIntFunction transformer,
      int basis,
      IntBinaryOperator reducer)
  • public long reduceKeysToLong(
      long parallelismThreshold,
      ToLongFunction transformer,
      long basis,
      LongBinaryOperator reducer)
  • public double reduceToDouble(
      long parallelismThreshold,
      ToDoubleBiFunction transformer,
      double basis,
      DoubleBinaryOperator reducer)
  • public int reduceToInt(
      long parallelismThreshold,
      ToIntBiFunction transformer,
      int basis,
      IntBinaryOperator reducer)
  • public long reduceToLong(
      long parallelismThreshold,
      ToLongBiFunction transformer,
      long basis,
      LongBinaryOperator reducer)
  • public Object reduceValues(
     long parallelismThreshold, BiFunction reducer)
  • public Object reduceValues(
      long parallelismThreshold,
      Function transformer,
      BiFunction reducer)
  • public double reduceValuesToDouble(
      long parallelismThreshold,
      ToDoubleFunction transformer,
      double basis,
      DoubleBinaryOperator reducer)
  • public int reduceValuesToInt(
      long parallelismThreshold,
      ToIntFunction transformer,
      int basis,
      IntBinaryOperator reducer)
  • public long reduceValuesToLong(
      long parallelismThreshold,
      ToLongFunction transformer,
      long basis,
      LongBinaryOperator reducer)
  • public Object remove(Object key)
  • public boolean remove(Object key, Object value)
  • public Object replace(Object key, Object value)
  • public boolean replace(
     Object key, Object oldValue, Object newValue)
  • public void replaceAll(BiFunction function)
  • public Object search(
      long parallelismThreshold,
      BiFunction searchFunction)
  • public Object searchEntries(
      long parallelismThreshold,
      Function searchFunction)
  • public Object searchKeys(
      long parallelismThreshold,
      Function searchFunction)
  • public Object searchValues(
      long parallelismThreshold,
      Function searchFunction)
  • public int size()
  • public String toString()
  • public Collection values()

Classe completamente implementata.

java.util.concurrent


 ThreadLocalRandom


  • public static ThreadLocalRandom current()
  • public DoubleStream doubles()
  • public DoubleStream doubles(
      double randomNumberOrigin,
      double randomNumberBound)
  • public DoubleStream doubles(long streamSize)
  • public DoubleStream doubles(
      long streamSize,
      double randomNumberOrigin,
      double randomNumberBound)
  • public IntStream ints()
  • public IntStream ints(
     int randomNumberOrigin, int randomNumberBound)
  • public IntStream ints(long streamSize)
  • public IntStream ints(
      long streamSize,
      int randomNumberOrigin,
      int randomNumberBound)
  • public LongStream longs()
  • public LongStream longs(long streamSize)
  • public LongStream longs(
     long randomNumberOrigin, long randomNumberBound)
  • public LongStream longs(
      long streamSize,
      long randomNumberOrigin,
      long randomNumberBound)
  • protected int next(int bits)
  • public boolean nextBoolean()
  • public double nextDouble()
  • public double nextDouble(double bound)
  • public double nextDouble(
     double origin, double bound)
  • public float nextFloat()
  • public double nextGaussian()
  • public int nextInt()
  • public int nextInt(int bound)
  • public int nextInt(int origin, int bound)
  • public long nextLong()
  • public long nextLong(long bound)
  • public long nextLong(long origin, long bound)
  • public void setSeed(long seed)

Classe completamente implementata.

java.util.function


 BiConsumer


  • public abstract void accept(Object p0, Object p1)
  • public BiConsumer andThen(BiConsumer after)

Classe completamente implementata.

java.util.function


 BiFunction


  • public BiFunction andThen(Function after)
  • public abstract Object apply(Object p0, Object p1)

Classe completamente implementata.

java.util.function


 BiPredicate


  • public BiPredicate and(BiPredicate other)
  • public BiPredicate negate()
  • public BiPredicate or(BiPredicate other)
  • public abstract boolean test(Object p0, Object p1)

Classe completamente implementata.

java.util.function


 BinaryOperator


  • public static BinaryOperator maxBy(
     Comparator comparator)
  • public static BinaryOperator minBy(
     Comparator comparator)

Classe completamente implementata.

java.util.function


 BooleanSupplier


  • public abstract boolean getAsBoolean()

Classe completamente implementata.

java.util.function


 Consumer


  • public abstract void accept(Object p0)
  • public Consumer andThen(Consumer after)

Classe completamente implementata.

java.util.function


 DoubleBinaryOperator


  • public abstract double applyAsDouble(
     double p0, double p1)

Classe completamente implementata.

java.util.function


 DoubleConsumer


  • public abstract void accept(double p0)
  • public DoubleConsumer andThen(DoubleConsumer after)

Classe completamente implementata.

java.util.function


 DoubleFunction


  • public abstract Object apply(double p0)

Classe completamente implementata.

java.util.function


 DoublePredicate


  • public DoublePredicate and(DoublePredicate other)
  • public DoublePredicate negate()
  • public DoublePredicate or(DoublePredicate other)
  • public abstract boolean test(double p0)

Classe completamente implementata.

java.util.function


 DoubleSupplier


  • public abstract double getAsDouble()

Classe completamente implementata.

java.util.function


 DoubleToIntFunction


  • public abstract int applyAsInt(double p0)

Classe completamente implementata.

java.util.function


 DoubleToLongFunction


  • public abstract long applyAsLong(double p0)

Classe completamente implementata.

java.util.function


 DoubleUnaryOperator


  • public DoubleUnaryOperator andThen(
     DoubleUnaryOperator after)
  • public abstract double applyAsDouble(double p0)
  • public DoubleUnaryOperator compose(
     DoubleUnaryOperator before)
  • public static DoubleUnaryOperator identity()

Classe completamente implementata.

java.util.function


 Function


  • public Function andThen(Function after)
  • public abstract Object apply(Object p0)
  • public Function compose(Function before)
  • public static Function identity()

Classe completamente implementata.

java.util.function


 IntBinaryOperator


  • public abstract int applyAsInt(int p0, int p1)

Classe completamente implementata.

java.util.function


 IntConsumer


  • public abstract void accept(int p0)
  • public IntConsumer andThen(IntConsumer after)

Classe completamente implementata.

java.util.function


 IntFunction


  • public abstract Object apply(int p0)

Classe completamente implementata.

java.util.function


 IntPredicate


  • public IntPredicate and(IntPredicate other)
  • public IntPredicate negate()
  • public IntPredicate or(IntPredicate other)
  • public abstract boolean test(int p0)

Classe completamente implementata.

java.util.function


 IntSupplier


  • public abstract int getAsInt()

Classe completamente implementata.

java.util.function


 IntToDoubleFunction


  • public abstract double applyAsDouble(int p0)

Classe completamente implementata.

java.util.function


 IntToLongFunction


  • public abstract long applyAsLong(int p0)

Classe completamente implementata.

java.util.function


 IntUnaryOperator


  • public IntUnaryOperator andThen(
     IntUnaryOperator after)
  • public abstract int applyAsInt(int p0)
  • public IntUnaryOperator compose(
     IntUnaryOperator before)
  • public static IntUnaryOperator identity()

Classe completamente implementata.

java.util.function


 LongBinaryOperator


  • public abstract long applyAsLong(long p0, long p1)

Classe completamente implementata.

java.util.function


 LongConsumer


  • public abstract void accept(long p0)
  • public LongConsumer andThen(LongConsumer after)

Classe completamente implementata.

java.util.function


 LongFunction


  • public abstract Object apply(long p0)

Classe completamente implementata.

java.util.function


 LongPredicate


  • public LongPredicate and(LongPredicate other)
  • public LongPredicate negate()
  • public LongPredicate or(LongPredicate other)
  • public abstract boolean test(long p0)

Classe completamente implementata.

java.util.function


 LongSupplier


  • public abstract long getAsLong()

Classe completamente implementata.

java.util.function


 LongToDoubleFunction


  • public abstract double applyAsDouble(long p0)

Classe completamente implementata.

java.util.function


 LongToIntFunction


  • public abstract int applyAsInt(long p0)

Classe completamente implementata.

java.util.function


 LongUnaryOperator


  • public LongUnaryOperator andThen(
     LongUnaryOperator after)
  • public abstract long applyAsLong(long p0)
  • public LongUnaryOperator compose(
     LongUnaryOperator before)
  • public static LongUnaryOperator identity()

Classe completamente implementata.

java.util.function


 ObjDoubleConsumer


  • public abstract void accept(Object p0, double p1)

Classe completamente implementata.

java.util.function


 ObjIntConsumer


  • public abstract void accept(Object p0, int p1)

Classe completamente implementata.

java.util.function


 ObjLongConsumer


  • public abstract void accept(Object p0, long p1)

Classe completamente implementata.

java.util.function


 Predicate


  • public Predicate and(Predicate other)
  • public static Predicate isEqual(Object targetRef)
  • public Predicate negate()
  • public static Predicate not(Predicate target)
  • public Predicate or(Predicate other)
  • public abstract boolean test(Object p0)

Classe completamente implementata.

java.util.function


 Supplier


  • public abstract Object get()

Classe completamente implementata.

java.util.function


 ToDoubleBiFunction


  • public abstract double applyAsDouble(
     Object p0, Object p1)

Classe completamente implementata.

java.util.function


 ToDoubleFunction


  • public abstract double applyAsDouble(Object p0)

Classe completamente implementata.

java.util.function


 ToIntBiFunction


  • public abstract int applyAsInt(Object p0, Object p1)

Classe completamente implementata.

java.util.function


 ToIntFunction


  • public abstract int applyAsInt(Object p0)

Classe completamente implementata.

java.util.function


 ToLongBiFunction


  • public abstract long applyAsLong(
     Object p0, Object p1)

Classe completamente implementata.

java.util.function


 ToLongFunction


  • public abstract long applyAsLong(Object p0)

Classe completamente implementata.

java.util.function


 UnaryOperator


  • public static UnaryOperator identity()

Classe completamente implementata.