通过脱糖提供的满足最低规格要求的 Java 11 及更高版本 API

Android Studio 支持使用多种 Java 11 及更高版本的 API,而无需为应用设置最低 API 级别。这意味着,如果您使用 Android 13(API 级别 33)中引入的 API,该代码也可在所有先前的版本上使用。Android 13 支持这些年来向 Android 引入的大多数 API。通过一个称为 API 脱糖的过程,DEX 编译器 (D8) 可让您在支持较低 Android 版本的应用中添加更多标准语言 API。

Java 11 以三种形式支持 API 脱糖:

  • 最低版本仅包含在旧设备上存在一些已知问题的 Android 框架并发集合的 java.util.function 软件包和替换类。
  • 默认版本实际上是 Java 8 API 脱糖更新到 Java 11 的升级版本。除了最低版本中的所有内容之外,它还包含 java.timejava.util.stream 软件包。
  • 除了默认版本中的所有内容之外,Nio 版本还包含 java.nio 软件包。

下面的可搜索表格显示了使用最新版本的 Android Gradle 插件并将 coreLibraryDesugaring 依赖项设置为 com.android.tools:desugar_jdk_libs_minimal:2.0.1 时包含了哪些 Java 11 及更高版本的库(如需了解详情,请参阅 API 脱糖。请在 build.gradlebuild.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()

完全实现的类。