How to use nested class with arsd.jni

fp dev at fp.com
Wed Mar 4 09:35:31 UTC 2020


Hello,

I have a problem using nested class with arsd.jni. Here is the 
java class :

//
// File Outer.java
//
public class Outer {
     public class Inner {
       void printHello() {
           System.out.println("inner class");
       }
     }
}

//
// D code
//
import std.stdio;
import arsd.jni;
final class Outer : JavaClass!("", Outer) {
	@Import this();
	final class Inner : JavaClass!("", Inner)
	{
            // if thoses 2 imports are removed it compiles
            // but this() and printHello() cannot be called
	   @Import this();
	   @Import void printHello();
	}
}
void main()
{
	auto jvm = createJvm();
	auto o = new Outer();
	Outer.Inner inner = o.Inner();
         inner.printHello();
}

The compiler ends with an error: "source\app.d(44,8): Error: 
class app.Outer.Inner is forward referenced when looking for 
__ctor". If we remove the 2 @Imports inside Inner, it compiles 
but the methods are unreachable !
What is the correct way to declare/use the nested Inner class ?

Thanks.


More information about the Digitalmars-d mailing list