Hey guys, a doubt about `inline class` what happen...
# announcements
b
Hey guys, a doubt about
inline class
what happens if I have an inline class as parameter of another inline class?
Copy code
inline class Bar(val number: Int)
inline class Foo(val bar: Bar)

Foo(Bar(1)) == 1?
b
You would need to access it via
Foo(Bar(1)).bar.number == 1
and then the compiler should unwrap it to just be
1 == 1
if your use case is really that simple
b
nice that's what I thought, thank you
b
I ran a test to see what the resulting code is for the following (obviously stripping some random stuff out)
Copy code
inline class Bar(val number: Int)
inline class Foo(val bar: Bar)

fun test() {
    if (Foo(Bar(1)).bar.number == 1) {
        println("YES")
    }
}
and it results in the following code in Java
Copy code
public final class Bar {
    public static int constructor-impl(int number) { return number; }
}

public final class Foo {
    public static int constructor-impl(int bar) { return bar; }
}

public static final void test() {
    if (Foo.constructor-impl(Bar.constructor-impl(1)) == 1) {
        System.out.println("YES");
    }
}
The key takeway that
constructor-impl
is receiving and returning an integer primitive and not boxed objects
👍 2
b
nice, thank you for helping