Source Code

A set of adaptors for types belonging to the Java language or Java SDK. Includes:

In addition, the functions javaClass() and javaClassFromInstance() allow Ceylon programs to obtain an instance of Class.

Platform: Java
By: The Ceylon Team
Packages
ceylon.interop.java
Dependencies
ceylon.collection1.3.3
java.base7
Aliases
ByteArrayLikeSource Codeshared ByteArrayLike=> Array<Bits>|ByteArray

An array whose elements can be represented as an Array<Byte>.

FloatArrayLikeSource Codeshared FloatArrayLike=> Array<Single>|Array<Double>|FloatArray|DoubleArray

An array whose elements can be represented as an Array<Float>.

IntegerArrayLikeSource Codeshared IntegerArrayLike=> Array<Short>|Array<Int>|Array<Long>|ShortArray|IntArray|LongArray

An array whose elements can be represented as an Array<Integer>.

JavaStringArrayLikeSource Codeshared JavaStringArrayLike=> ObjectArray<String>|Array<String>|Array<String?>

An array whose elements can be represented as an ObjectArray<JavaString>.

StringArrayLikeSource Codeshared StringArrayLike=> ObjectArray<JavaString>|Array<JavaString?>|Array<JavaString>

An array whose elements can be represented as an Array<String?>.

Functions
createJavaBooleanArraySource Codeshared BooleanArray createJavaBooleanArray({Boolean*} booleans)

Create a new BooleanArray, that is, a Java boolean[] array, with the given elements.

createJavaByteArraySource Codeshared ByteArray createJavaByteArray({Byte*} elements)

Create a new ByteArray, that is, a Java byte[] array, with the given elements.

createJavaDoubleArraySource Codeshared DoubleArray createJavaDoubleArray({Float*} elements)

Create a new DoubleArray, that is, a Java double[] array, with the given elements.

createJavaFloatArraySource Codeshared FloatArray createJavaFloatArray({Float*} elements)

Create a new FloatArray, that is, a Java float[] array, with the given elements.

createJavaIntArraySource Codeshared IntArray createJavaIntArray({Integer*} elements)

Create a new IntArray, that is, a Java int[] array, with the given elements.

createJavaLongArraySource Codeshared LongArray createJavaLongArray({Integer*} elements)

Create a new LongArray, that is, a Java long[] array, with the given elements.

createJavaObjectArraySource Codeshared ObjectArray<Element> createJavaObjectArray<Element>({Element?*} elements)
given Element satisfies Object

Create a new ObjectArray, that is, a Java array that is a subtype of Object[], with the given elements.

Throws
  • AssertionError

    if Element is a union or intersection type, or the bottom type Nothing

createJavaShortArraySource Codeshared ShortArray createJavaShortArray({Integer*} elements)

Create a new ShortArray, that is, a Java short[] array, with the given elements.

createJavaStringArraySource Codeshared ObjectArray<JavaString> createJavaStringArray({String*} elements)

Create a new string array, that is, a Java String[] array, with the given elements.

javaAnnotationClassSource Codeshared Class<out Type> javaAnnotationClass<Type>()
given Type satisfies Annotation

Deprecated: use classForAnnotationType

A Java Class object representing the Java annotation type corresponding to the given Ceylon Type.

javaBooleanArraySource Codeshared BooleanArray javaBooleanArray(Array<Boolean>|Array<Bool> array)

The BooleanArray, that is, the Java boolean[] array, underlying the given Ceylon array. Changes made to this Java array will be reflected in the given Array and vice versa.

javaByteArraySource Codeshared ByteArray javaByteArray(Array<Byte>|Array<Bits> array)

The ByteArray, that is, the Java byte[] array underlying the given Ceylon array. Changes made to this Java array will be reflected in the given Array and vice versa.

javaCharArraySource Codeshared CharArray javaCharArray(Array<Char> array)

The CharArray, that is, the Java char[] array underlying the given Ceylon array. Changes made to this Java array will be reflected in the given Array and vice versa.

javaClassSource Codeshared Class<Type> javaClass<Type>()
given Type satisfies Object

Deprecated: use classForType

A Java Class object representing the given Type.

javaClassFromDeclarationSource Codeshared Class<out Object> javaClassFromDeclaration(ClassOrInterfaceDeclaration declaration)

Deprecated: use classForDeclaration

A Java Class object representing the given ClassOrInterfaceDeclaration.

javaClassFromInstanceSource Codeshared Class<out Type> javaClassFromInstance<Type>(Type instance)
given Type satisfies Object

Deprecated: use classForInstance

A Java Class object representing the concrete type of the given instance.

javaClassFromModelSource Codeshared Class<out Type> javaClassFromModel<Type>(ClassOrInterface<Type> model)
given Type satisfies Object

Deprecated: use classForModel

A Java Class object representing the given ClassOrInterface.

javaDoubleArraySource Codeshared DoubleArray javaDoubleArray(Array<Float>|Array<Double> array)

The DoubleArray, that is, the Java double[] array underlying the given Ceylon array. Changes made to this Java array will be reflected in the given Array and vice versa.

javaFloatArraySource Codeshared FloatArray javaFloatArray(Array<Single> array)

The FloatArray, that is, the Java float[] array underlying the given Ceylon array. Changes made to this Java array will be reflected in the given Array and vice versa.

javaIntArraySource Codeshared IntArray javaIntArray(Array<Character>|Array<Int> array)

The IntArray, that is, the Java int[] array underlying the given Ceylon array. Changes made to this Java array will be reflected in the given Array and vice versa.

javaLongArraySource Codeshared LongArray javaLongArray(Array<Integer>|Array<Long> array)

The LongArray, that is, the Java long[] array underlying the given Ceylon array. Changes made to this Java array will be reflected in the given Array and vice versa.

javaObjectArraySource Codeshared ObjectArray<Element> javaObjectArray<Element>(Array<Element?> array)
given Element satisfies Object

The ObjectArray, that is, the Java Object[] array underlying the given Ceylon array. Changes made to this Java array will be reflected in the given Array and vice versa.

Throws
  • AssertionError

    if Element is a union or intersection type, or the bottom type Nothing

javaShortArraySource Codeshared ShortArray javaShortArray(Array<Short> array)

The ShortArray, that is, the Java short[] array underlying the given Ceylon array. Changes made to this Java array will be reflected in the given Array and vice versa.

javaStackTraceSource Codeshared StackTraceElement[] javaStackTrace(Throwable throwable)

Deprecated: use stackTrace

The stack trace information for the given Throwable as a sequence of Java StackTraceElements, or the empty sequence if no stack trace information is available. The first element of the sequence is the top of the stack, that is, the most deeply nested stack frame. This is usually the stack frame in which the given Throwable was created and thrown.

javaStringSource Codeshared JavaString javaString(String string)

Deprecated: use nativeString

The JavaString underlying the given Ceylon String.

javaStringArraySource Codeshared ObjectArray<JavaString> javaStringArray(Array<String> array)

The string array, that is, the Java String[] array underlying the given Ceylon array. Changes made to this Java array will be reflected in the given Array and vice versa.

synchronizeSource Codeshared Return synchronize<Return>(Object on, Return do())

Runs the do() callback in a block synchronized on on.

value newCount = synchronize(this, () {
   return count++;
});

This is an alternative to direct use of the annotation synchronized, allowing synchronization on a given object.

toByteArraySource Codeshared Array<Byte> toByteArray(ByteArrayLike array)

Create a new Array<Byte> with the same elements as the given array.

toFloatArraySource Codeshared Array<Float> toFloatArray(FloatArrayLike array)

Create a new Array<Float> with the same elements as the given array.

toIntegerArraySource Codeshared Array<Integer> toIntegerArray(IntegerArrayLike array)

Create a new Array<Integer> with the same elements as the given array.

toJavaStringArraySource Codeshared ObjectArray<JavaString> toJavaStringArray(JavaStringArrayLike array)

Create a new Java string array, that is, a Java String[], with the same elements as the given array of Ceylon strings.

toStringArraySource Codeshared Array<String?> toStringArray(StringArrayLike array)

Create a new Ceylon string array, that is, an Array<String?> with the same elements as the given array of Java strings.

Classes
CeylonBooleanIterableSource Codeshared CeylonBooleanIterable

A Ceylon Iterable<ceylon.language::Boolean> that adapts an instance of Java's java.lang::Iterable (java.lang::Iterable)<java.lang::Boolean>, allowing its elements to be iterated using a for loop.

CeylonByteIterableSource Codeshared CeylonByteIterable

A Ceylon Iterable<ceylon.language::Byte> that adapts an instance of Java's java.lang::Iterable (java.lang::Iterable)<java.lang::Byte>, allowing its elements to be iterated using a for loop.

CeylonCollectionSource Codeshared CeylonCollection<out Element>

A Ceylon Collection that wraps a JCollection.

CeylonDestroyableSource Codeshared CeylonDestroyable<Resource>
given Resource satisfies AutoCloseable

A Ceylon Destroyable that adapts an instance of Java's AutoCloseable, allowing it to be used as a resource in the try construct.

try (inputStream = CeylonDestroyable(FileInputStream(file)) {
    Integer byte = inputStream.resource.read();
    ...
}

Note: Since Ceylon 1.2.1 it is possible to use AutoCloseable directly in a Ceylon try statement:

try (inputStream = FileInputStream(file)) {
    ...
}
CeylonFloatIterableSource Codeshared CeylonFloatIterable

A Ceylon Iterable<ceylon.language::Float> that adapts an instance of Java's java.lang::Iterable (java.lang::Iterable)<java.lang::Double> or java.lang::Iterable<java.lang::Float>, allowing its elements to be iterated using a for loop.

CeylonIntegerIterableSource Codeshared CeylonIntegerIterable

A Ceylon Iterable<ceylon.language::Integer> that adapts an instance of Java's java.lang::Iterable (Iterable)<java.lang::Long>, java.lang::Iterable<java.lang::Integer> or java.lang::Iterable<java.lang::Short> allowing its elements to be iterated using a for loop.

CeylonIterableSource Codeshared CeylonIterable<Element>

A Ceylon Iterable that adapts an instance of Java's JIterable, allowing its elements to be iterated using a for loop.

IntArray ints = ... ;
for (int in CeylonIterable(Arrays.asList(*ints.array))) {
    ...
}

If the given CeylonIterable.iterable contains null elements, an optional Element type must be explicitly specified, for example:

CeylonIterable<String?>(javaStringStream)

If a non-optional Element type is specified, an AssertionError will occur whenever a null value is encountered while iterating the stream.

Note: Since Ceylon 1.2.1 it is possible to use JIterable directly in a Ceylon for statement:

JavaIterable<Foo> iterable = ... ;
for (foo in iterable) {
    ...
}
CeylonIteratorSource Codeshared CeylonIterator<T>

A Ceylon Iterator that adapts an instance of Java's JIterator.

CeylonListSource Codeshared CeylonList<out Element>

A Ceylon List that wraps a JList.

If the given CeylonList.list contains null elements, an optional Element type must be explicitly specified, for example:

CeylonList<String?>(javaStringList)

If a non-optional Element type is specified, an AssertionError will occur whenever a null value is encountered while iterating the list.

CeylonMapSource Codeshared CeylonMap<out Key,out Item>
given Key satisfies Object

A Ceylon Map that wraps a JMap.

If the given CeylonMap.map contains null elements, an optional Item type must be explicitly specified, for example:

CeylonMap<String,Object?>(javaStringObjectMap)

If a non-optional Item type is specified, an AssertionError will occur whenever a null item is encountered while iterating the map.

CeylonMutableListSource Codeshared CeylonMutableList<Element>
given Element satisfies Object

A Ceylon MutableList that wraps a JList.

If the given CeylonMutableList.list contains null elements, an optional Element type must be explicitly specified, for example:

CeylonMutableList<String?>(javaStringList)

If a non-optional Element type is specified, an AssertionError will occur whenever a null value is encountered while iterating the list.

CeylonMutableMapSource Codeshared CeylonMutableMap<Key,Item>
given Key satisfies Object
given Item satisfies Object

A Ceylon MutableMap that wraps a JMap.

If the given CeylonMutableMap.map contains null elements, an optional Item type must be explicitly specified, for example:

CeylonMap<String,Object?>(javaStringObjectMap)

If a non-optional Item type is specified, an AssertionError will occur whenever a null item is encountered while iterating the map.

CeylonMutableSetSource Codeshared CeylonMutableSet<Element>
given Element satisfies Object

A Ceylon MutableSet that wraps a JSet.

CeylonSetSource Codeshared CeylonSet<out Element>
given Element satisfies Object

A Ceylon Set that wraps a JSet.

CeylonStringIterableSource Codeshared CeylonStringIterable

A Ceylon Iterable<ceylon.language::String> that adapts an instance of Java's java.lang::Iterable (java.lang::Iterable)<java.lang::String>, allowing its elements to be iterated using a for loop.

CeylonStringListSource Codeshared CeylonStringList

A List with keys of type String that wraps a List with keys of type java.lang::String.

This class can be used to wrap a java.util::List if the Java map is first wrapped with CeylonList:

CeylonStringList(CeylonList(javaList))

If the given list is a MutableList, use CeylonStringMutableList.

CeylonStringMapSource Codeshared CeylonStringMap<out Item>

A Map with keys of type String that wraps a Map with keys of type java.lang::String.

This class can be used to wrap a java.util::Map if the Java map is first wrapped with CeylonMap:

CeylonStringMap(CeylonMap(javaMap))

If the given map is a MutableMap, use CeylonStringMutableMap.

CeylonStringMutableListSource Codeshared CeylonStringMutableList

A MutableList with elements of type ceylon.language::String that wraps a MutableList with elements of type java.lang::String.

This class can be used to wrap a java.util::List if the Java list is first wrapped with CeylonMutableList:

   CeylonStringMutableList(CeylonMutableList(javaList))

If the given list is not a MutableList, use CeylonStringList.

CeylonStringMutableMapSource Codeshared CeylonStringMutableMap<Item>

A MutableMap with keys of type ceylon.language::String that wraps a MutableMap with keys of type java.lang::String.

This class can be used to wrap a java.util::Map if the Java map is first wrapped with CeylonMutableMap:

   CeylonStringMutableMap(CeylonMutableMap(javaMap))

If the given list is not a MutableMap, use CeylonStringMap.

JavaCloseableSource Codeshared JavaCloseable<Resource>
given Resource satisfies Destroyable

A Java AutoCloseable that adapts an instance of Ceylon's Destroyable, allowing it to be used as a resource in the try construct.

JavaCollectionSource Codeshared JavaCollection<E>

A Java Collection that wraps a Ceylon Collection. This collection is unmodifiable, throwing UnsupportedOperationException from mutator methods.

JavaComparatorSource Codeshared JavaComparator<Element>

A Java JComparator that wraps a function returning Comparison. The given JavaComparator.compareElements() function will be used to compare null values if Element covers Null. Otherwise, nulls will be ordered according to the JavaComparator.nulls parameter.

JavaIterableSource Codeshared JavaIterable<Element>

A Java JIterable that wraps a Ceylon Iterable.

JavaIteratorSource Codeshared JavaIterator<T>

A Java JIterator that wraps a Ceylon Iterator. This iterator is unmodifiable, throwing UnsupportedOperationException from JavaIterator.remove().

JavaListSource Codeshared JavaList<E>

A Java List that wraps a Ceylon List. This list is unmodifiable, throwing UnsupportedOperationException from mutator methods.

JavaMapSource Codeshared JavaMap<K,V>
given K satisfies Object
given V satisfies Object

A Java Map that wraps a Ceylon Map. This map is unmodifiable, throwing UnsupportedOperationException from mutator methods.

JavaRunnableSource Codeshared JavaRunnable

A Java Runnable that executes the given function.

JavaSetSource Codeshared JavaSet<E>
given E satisfies Object

A Java Set that wraps a Ceylon Set. This set is unmodifiable, throwing UnsupportedOperationException from mutator methods.

JavaStringListSource Codeshared JavaStringList

A List with keys of type java.lang::String that wraps a List with keys of type String.

JavaList(JavaStringList(ceylonList))
JavaStringMapSource Codeshared JavaStringMap<Item>

A Map with keys of type java.lang::String that wraps a Map with keys of type String.

JavaMap(JavaStringMap(ceylonMap))
JavaThreadSource Codeshared JavaThread

A Java Thread that executes the given function.