0

I have the following classes in Java:

public class Parent<T>{
    public class Inner {
        private T item;
        //...
    }
    //...
} 

public class Child<T> extends Parent<T> {
    //...
}

I now want to use this in the following way in Kotlin:

fun handle(test: Child<Something>.Inner) {
    // Error: Unresolved Reverence: Inner
}

If I do the same thing in Java, it works:

public void handle(Child<Something>.Inner test) {
    //..
}

How can I do this in Kotlin?

user1892364
  • 259
  • 2
  • 12
  • `Parent.Inner` seems to work. – EpicPandaForce Aug 01 '18 at 11:42
  • That is right, but if I wanted to use the parent there I would do so. – user1892364 Aug 01 '18 at 12:00
  • Consider filing an issue on the Kotlin YouTrack with this. – Marko Topolnik Aug 01 '18 at 12:02
  • Can you try something like `fun handle(test: Inner) { ... }` ? `Inner` without `Child<>`. – Demigod Aug 01 '18 at 12:44
  • @Demigod The whole point for me is to use this with http://greenrobot.org/eventbus/ where the subscribers check on the class that is pushed on the bus, so I do not get subscribed on events I do not want. So if I have Child1 and Child2 I would get both if I am not able to lock it to the one I want. So maybe it would be possible with another typecheck, but having this in every subscriber would be a lot of overhead. – user1892364 Aug 01 '18 at 13:02
  • if it's for event bus i'm surprised a regular inner class works instead of `static class` in java – EpicPandaForce Aug 01 '18 at 13:09
  • @user1892364, so what do you want is to allow to pas `Child1` but forbid to pass `Child2`? Despite that in Java you can write something like this `public void handle(Child.Inner test) { ... }` you also can pass to this methid `Child2.Inner`.. So it kinda don't locks with the inherited class type. – Demigod Aug 01 '18 at 13:55
  • 1
    @MarkoTopolnik issue was filed here: https://youtrack.jetbrains.com/issue/KT-25836 – user1892364 Aug 02 '18 at 19:48
  • Possible duplicate of [Accessing static inner class defined in Java, through derived class](https://stackoverflow.com/questions/55917371/accessing-static-inner-class-defined-in-java-through-derived-class) – smac89 Oct 10 '19 at 08:07

0 Answers0