Skip to content

Instantly share code, notes, and snippets.

@ItsDoot
Created November 1, 2017 02:17
Show Gist options
  • Save ItsDoot/de109bdddbd22e4327334e62693076e2 to your computer and use it in GitHub Desktop.
Save ItsDoot/de109bdddbd22e4327334e62693076e2 to your computer and use it in GitHub Desktop.
Unsafe type casting in Ceylon (through Java)
import ceylon.language.SharedAnnotation$annotation$;
import com.redhat.ceylon.compiler.java.metadata.*;
import com.redhat.ceylon.compiler.java.runtime.model.TypeDescriptor;
import java.lang.Object;
@Ceylon(major = 8)
@Method
public class unsafeCast_ {
private unsafeCast_() {
}
@SuppressWarnings("unchecked")
@SharedAnnotation$annotation$
@TypeInfo("T")
@TypeParameters({@TypeParameter(value = "T", variance = Variance.IN)})
public static <T> T unsafeCast(@Ignore final TypeDescriptor $reified$T,
@Name("o") @TypeInfo("ceylon.language::Anything") final Object o) {
return (T) o;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment