Hello I have a question relating inner classes in ...
# android
a
Hello I have a question relating inner classes in Java I'm having troubles with. I have a utility class in which I hold various enum classes. There is no problem accessing them in Java classes, but when I try to access them in a Kotlin class, I get Unresolved reference: UtilityClass Utility class looks like this
Copy code
public final class UtilityClass {

    private UtilityClass() {
        // Utility class
    }

    public enum FirstEnum {
        FIRST_OPTION, SECOND_OPTION, THIRD_OPTION, NONE
    }
}
While the the data class in Kotlin is as follows
Copy code
data class KotlinClass(val option: UtilityClass.FirstEnum = UtilityClass.FirstEnum.NONE)
Does anyone maybe know why I get "Unresolved reference: UtilityClass" trying to access the enum from my utility class? Both classes are in same package, so no imports required, I've tried moving either class in another package, but the issue persists I had no luck finding a solution for this, I can't find anything even remotely similar to this problem
d
Your utility class isn't static
a
Yes, but I cannot make a top level class static
d
Oh, I thought it was related to inner class, but actually I just tried this out and it works fine O.o
a
For me it doesn't work. I have kotlin version 1.3.61, although I don't think it's relevant
d
I tried on 1.3.72
a
I tried this on a different project and it worked. Maybe it's a problem with the project, but I have no idea what exactly.
c
If you are trying to write a utility class in Kotlin you'd probably have better luck defining it as an
object
instead of a
class
a
Yes, but the Utility class should remain Java class. That's the problem, having an kotlin object as the utility class works, I get the error when the utility class is Java class
c
What's the stack trace? The unresolved reference makes it sound like the import is missing. I recreated this on my end and it was working for me
a
There shouldn't be import problems, as both classes are from same package. This is the stacktrace
Untitled
g
It’s not an actuall compilation error, it’s gradle stacktrace, check your build logs
a
But the build logs says the error I don't understand ,*Unresolved reference: UtilityClass"
g
Okay, make sense
so it cannot resolve this class
could you show screenshot from IDE? is it resolved?
Maybe some another UtilityClass is imported, so it doesn’t see your default package import
Because code which you show it fine and it should work. Maybe you could reporoduce on a sample project
also, you sure that your Kotlin class has package itself?