Class ArbitraryInstances
- java.lang.Object
-
- com.google.common.testing.ArbitraryInstances
-
@Beta @GwtIncompatible public final class ArbitraryInstances extends Object
Supplies an arbitrary "default" instance for a wide range of types, often useful in testing utilities.Covers arrays, enums and common types defined in
java.lang,java.lang.reflect,java.io,java.nio,java.math,java.util,java.util.concurrent,java.util.regex,com.google.common.base,com.google.common.collectandcom.google.common.primitives. In addition, if the type exposes at least one public static final constant of the same type, one of the constants will be used; or if the class exposes a public parameter-less constructor then it will be "new"d and returned.All default instances returned by
get(java.lang.Class<T>)are generics-safe. Clients won't get type errors for usingget(Comparator.class)as aComparator<Foo>, for example. Immutable empty instances are returned for collection types;""for string;0for number types; reasonable default instance for other stateless types. For mutable types, a fresh instance is created each timeget()is called.- Since:
- 12.0
- Author:
- Kevin Bourrillion, Ben Yu
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> @Nullable Tget(Class<T> type)Returns an arbitrary instance fortype, ornullif no arbitrary instance can be determined.
-