#2757 Java FFI: using [java] nestest class

Ilove:= Mon 24 Jun

I have something like this in java: test.jar

package test; public class C1 { public static class C2 { } }

How could I import it in Fantom? Anything I tried without succeed.

using [java] test::C1::C2

using [java] test::C1.C2


All failed. Please help. On Java we only has dot so it's really simple. On Fantom, we also have :: so thing got very complicated. Please update the document to add such example ussage. Thanks.

SlimerDude Mon 24 Jun

Hiya, Inner Java classes are mentioned in the JavaFFI under innerClasses. The notation you're missing is:

using [java] test::C1$C2 as C2

It's a bit messy, but it should work.

Ilove:= Mon 24 Jun

Thank you, SlimmerDude. You saved my day! My eyes are so bad now as I missed this section on the document even having read it so many times :(

While waiting for help I tried with a small test and it seemed that Fan doesn't support nested classes like Java does.

When I write something like this:

public class A { public static class B { ... } }

F4 always present me with errors :(

SlimerDude Mon 24 Jun

Correct, Fantom does not support inner classes.

Brian reasoned it in this post:

Fantom doesn't support inner classes largely for two reasons:

1) you often use closures and

b) to keep type namespace simple and flat (to avoid overloads of the dot operator)

Ilove:= Mon 24 Jun

This is reasonable. I only want to use this java class. I don't think I will ever want to use nested class in Fan :)

Login or Signup to reply.