最小限の仕様の脱糖で使用可能な Java 11+ API

Android Studio では、アプリの最小 API レベルを必要とせずに、多数の Java 11+ API の使用がサポートされています。つまり、Android 13(API レベル 33)で導入された API を使用すると、そのコードは以前のバージョンでも動作します。長年にわたって Android に導入された API のほとんどは、Android 13 でサポートされています。API の脱糖と呼ばれるプロセスにより、DEX コンパイラ(D8)を使用して、古いバージョンの Android をサポートするアプリに標準的な言語 API を組み込むことができます。

Java 11 でサポートされている API の脱糖には、次の 3 つの種類があります。

  • 最小バージョン: 古いデバイスで既知の問題が起きていた一部の Android フレームワークの同時実行コレクションの java.util.function パッケージと後継クラスのみが含まれます。
  • デフォルト バージョン: 実質的には、Java 11 にアップデートされた Java 8 API の脱糖のアップグレード版です。最小バージョンのすべてに加えて、java.time パッケージと java.util.stream パッケージが含まれています。
  • nio バージョン: デフォルト バージョンのすべてに加えて、java.nio パッケージが含まれています。

coreLibraryDesugaring 依存関係を com.android.tools:desugar_jdk_libs_minimal:2.0.1 に設定して最新バージョンの Android Gradle プラグインを使用する際に利用できる Java 11+ ライブラリを、以下の検索可能な表に示します(詳細については、API の脱糖をご覧ください)。このプロパティは build.gradle ファイルまたは build.gradle.kts ファイルで設定します。

パッケージ +
クラス、
列挙型、
インターフェース
コンストラクタ、
プロパティ、
メソッド
メモ
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()

Android T に存在する一部のメソッド(8)はサポートされていません。

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()

完全に実装されたクラスです。

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)

完全に実装されたクラスです。

java.util.function


 BiConsumer


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

完全に実装されたクラスです。

java.util.function


 BiFunction


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

完全に実装されたクラスです。

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)

完全に実装されたクラスです。

java.util.function


 BinaryOperator


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

完全に実装されたクラスです。

java.util.function


 BooleanSupplier


  • public abstract boolean getAsBoolean()

完全に実装されたクラスです。

java.util.function


 Consumer


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

完全に実装されたクラスです。

java.util.function


 DoubleBinaryOperator


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

完全に実装されたクラスです。

java.util.function


 DoubleConsumer


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

完全に実装されたクラスです。

java.util.function


 DoubleFunction


  • public abstract Object apply(double p0)

完全に実装されたクラスです。

java.util.function


 DoublePredicate


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

完全に実装されたクラスです。

java.util.function


 DoubleSupplier


  • public abstract double getAsDouble()

完全に実装されたクラスです。

java.util.function


 DoubleToIntFunction


  • public abstract int applyAsInt(double p0)

完全に実装されたクラスです。

java.util.function


 DoubleToLongFunction


  • public abstract long applyAsLong(double p0)

完全に実装されたクラスです。

java.util.function


 DoubleUnaryOperator


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

完全に実装されたクラスです。

java.util.function


 Function


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

完全に実装されたクラスです。

java.util.function


 IntBinaryOperator


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

完全に実装されたクラスです。

java.util.function


 IntConsumer


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

完全に実装されたクラスです。

java.util.function


 IntFunction


  • public abstract Object apply(int p0)

完全に実装されたクラスです。

java.util.function


 IntPredicate


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

完全に実装されたクラスです。

java.util.function


 IntSupplier


  • public abstract int getAsInt()

完全に実装されたクラスです。

java.util.function


 IntToDoubleFunction


  • public abstract double applyAsDouble(int p0)

完全に実装されたクラスです。

java.util.function


 IntToLongFunction


  • public abstract long applyAsLong(int p0)

完全に実装されたクラスです。

java.util.function


 IntUnaryOperator


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

完全に実装されたクラスです。

java.util.function


 LongBinaryOperator


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

完全に実装されたクラスです。

java.util.function


 LongConsumer


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

完全に実装されたクラスです。

java.util.function


 LongFunction


  • public abstract Object apply(long p0)

完全に実装されたクラスです。

java.util.function


 LongPredicate


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

完全に実装されたクラスです。

java.util.function


 LongSupplier


  • public abstract long getAsLong()

完全に実装されたクラスです。

java.util.function


 LongToDoubleFunction


  • public abstract double applyAsDouble(long p0)

完全に実装されたクラスです。

java.util.function


 LongToIntFunction


  • public abstract int applyAsInt(long p0)

完全に実装されたクラスです。

java.util.function


 LongUnaryOperator


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

完全に実装されたクラスです。

java.util.function


 ObjDoubleConsumer


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

完全に実装されたクラスです。

java.util.function


 ObjIntConsumer


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

完全に実装されたクラスです。

java.util.function


 ObjLongConsumer


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

完全に実装されたクラスです。

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)

完全に実装されたクラスです。

java.util.function


 Supplier


  • public abstract Object get()

完全に実装されたクラスです。

java.util.function


 ToDoubleBiFunction


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

完全に実装されたクラスです。

java.util.function


 ToDoubleFunction


  • public abstract double applyAsDouble(Object p0)

完全に実装されたクラスです。

java.util.function


 ToIntBiFunction


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

完全に実装されたクラスです。

java.util.function


 ToIntFunction


  • public abstract int applyAsInt(Object p0)

完全に実装されたクラスです。

java.util.function


 ToLongBiFunction


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

完全に実装されたクラスです。

java.util.function


 ToLongFunction


  • public abstract long applyAsLong(Object p0)

完全に実装されたクラスです。

java.util.function


 UnaryOperator


  • public static UnaryOperator identity()

完全に実装されたクラスです。