0

With

shared T f<T>(T t){
  return t;
}

I expected something like

mod.f_.f[Integer](1)

to work in scala, where [Integer] is the type parameter. But it doesn't accept type parameters.

And why does scala see a getter instead of a function for

shared Integer(Integer) fi = f<Integer>;

I expected Integer(Integer) to be enough to tell the compiler that to expose a function to scala.

1 Answers1

7

I don’t know Scala, so I can only help out with the Java part, but here’s how you call that function from Java:

f_.f(Integer.$TypeDescriptor$, Integer.instance(1))

or:

f_.<Integer>f(Integer.$TypeDescriptor$, Integer.instance(1))

Ceylon features reified generics, so type parameters turn into regular parameters, and you have to supply the type descriptor objects of the type arguments. Ceylon classes and interfaces have a static $TypeDescriptor$ member you can use for that; I don’t know how other stuff (Java classes, union and intersection types, …) works off the top of my head, but you can write the equivalent invocation in Ceylon and look at the generated Java code by compiling it with --verbose=code.

Here’s a full, working example with your f function and a Java class G that calls it: gist

Lucas Werkmeister
  • 2,584
  • 1
  • 17
  • 31
  • 3
    @Michael You can use `TypeDescriptor.klass(Whatever.class)` to get a `TypeDescriptor` for the Java or Scala class `Whatever`. – Gavin King Apr 17 '17 at 21:23