Ceylon/Java interop by Tako Schotanus

  • 9,716 views
Uploaded on

Discover how Ceylon and Java work together.

Discover how Ceylon and Java work together.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
9,716
On Slideshare
0
From Embeds
0
Number of Embeds
23

Actions

Shares
Downloads
0
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Java Interop Tako Schotanus, Red Hat
  • 2. Geecon: An Introduction to Ceylon Combined sources public class JavaClass { int count(String name) { ... } } shared void run() { value jc = JavaClass(); print( jc.count("thing") ); }
  • 3. Geecon: An Introduction to Ceylon Legacy code • Maven ceylon compile --rep aether helloworld/1.0 • Import-jar ceylon import-jar --jar lib/myjar-3.0 com.example.myjar/3.0 module “helloworld” 1.0 { import org.hibernate.core “4.2.1.Final”; import com.example.myjar “3.0”; }
  • 4. Geecon: An Introduction to Ceylon Primitive types • Integer <-> long, int, short, byte • Float <-> double, float • Boolean <-> boolean • Character --> int, char • String <-> j.l.String • No Byte type (might come in future?) • Boxing with generics
  • 5. Geecon: An Introduction to Ceylon Special name handling print(iCONSTANT); value v = Isome_class() import com.example { constant = CONSTANT, SomeClass = some_class } print(constant); value v = SomeClass()
  • 6. Geecon: An Introduction to Ceylon Null handling public class JavaClass { int foo(int param) { ... } Integer bar(Integer param) { return null; } } Integer i1 = jc.foo(5); Integer i2 = jc.foo(null); // Error Integer? i3 = jc.bar(null); Integer i4 = jc.bar(5); // Compiles Ok, runtime error
  • 7. Geecon: An Introduction to Ceylon Properties public class JavaClass { shared class ClassClass() { int getFoo() { ... } Integer foo; int getBar() { ... } variable Integer bar; void setBar(int bar) { ... } void setBaz(Integer baz) { ... } void setBaz(int baz) { ... } } }
  • 8. Geecon: An Introduction to Ceylon Properties (contd.) public class JavaClass { shared class ClassClass() { int getFoo() { return 0; } int getBar() { return b; } Integer bar { return b; } void setBar(int bar) { ... } assign bar { ... } void setBaz(int baz) { ... } } Integer foo { return 0; } void setBaz(Integer baz) { ... } }
  • 9. Geecon: An Introduction to Ceylon Overloading Ceylon doesn't have overloading but does support it for Java where possible public class JavaClass { void foo(int param) { ... } void foo(String param) { ... } } jc.foo(5); jc.foo(“bar”);
  • 10. Geecon: An Introduction to Ceylon Overloading (contd.) public class JavaClass { void foo(long param) { ... } void foo(short param) { ... } } import java.lang { Short } jc.foo(5); jc.foo(Short(5).shortValue());
  • 11. Geecon: An Introduction to Ceylon JDK Modules (JigSaw) • JDK divided in JigSaw compatible modules • Always available but must be explicitly imported module “helloworld” 1.0 { import java.base “7”; import javax.xml “7”; } import java.lang { Short } import javax.xml { ... }
  • 12. Geecon: An Introduction to Ceylon Arrays • BooleanArray --> boolean[ ] • IntArray --> int[ ] • ByteArray, CharArray, etc • ShortArray(...).array --> Array<j.l.Short> • Array<T>
  • 13. Geecon: An Introduction to Ceylon Annotations • Integration with existing frameworks that use annotations possible import javax.annotation { postConstruct } postConstruct shared void reset() { // Clean up after ourselves this.count = 0; this.userNumber = 0; }
  • 14. Geecon: An Introduction to Ceylon ceylon.interop.java • Part of the SDK • Useful functions like – javaClassFromInstance() – javaString() – JavaIterable / JavaIterator – CeylonIterable / CeylonIterator
  • 15. Geecon: An Introduction to Ceylon JavaScript interop • All revolves around dynamic dynamic value target; dynamic { target = jQuery(“#target”); target.select(function() { ... }); } • Typed interfaces in the future?
  • 16. Geecon: An Introduction to Ceylon