Does anyone know what's going on here?
# announcements
l
Does anyone know what's going on here?
h
i think it needs to be a static function?
l
Like
@JvmStatic
?
h
inside companion object, i think so
l
Companion object of an
object
?
h
inside the class's companion object
l
The class is an
object
...
h
oh, i didn't realise
l
image.png
h
try @JvmStatic. does it work?
l
Static overrides don't even make sense!
h
🤷
l
The superclass has a static
main
... why would this exist in the subclass?
h
does it work if you don't extend PApplet?
l
Yep!
This is the declaration inside of
PApplet
! So why would this matter in a subclass?
h
You answered it yourself. "Static overrides don't make sense"
l
Exactly because static methods don't exist in subclasses! So why does Kotlin want me to override it because my method has the same signature of a static method of a superclass?
That static
main
should not exist in my subclass! So I should be able to define my own without having to override anything!
This is really weird, unexpected behavior for me! How come this is happening? Is this intended or a bug?
a
Tryna remove out in generics and donot use the override and annotate with @JvmStatic.
l
Makes no difference!
Also removing
out
isn't really necessary... it has nothing to do with this...
a
Screenshot_20200622-130107.jpg
l
Yeah, they're all static as far as I can tell! How come I can't make a method with the same signature in a subclass?
a
I think it already has a main function, and you won't be able to override the static functions.
l
It's not overriding the static functions, static functions are
PApplet.whatever
and subclasses don't inherit static functions!
Or... maybe they do? https://stackoverflow.com/a/10292034 This answer says that static functions are inherited, but you can still override them, I think?
a
I'd suggest declaring main outside :)
t
yes, it is a jvm thing. you can have
Copy code
class MyTest {
  public static void method() {

  }
}

MyTest test = new MyTest();
myTest.method();
so it is a method also on the instantiate object. but it cannot be overriden
Copy code
class ExtMyTest extends MyTest {
  public void method() {

  }
}
compile error in java as well
l
Which is what I had to do to make it work! Which is annoying because I have to do this!
Because
runSketch
is protected...
@thanksforallthefish Can't you define a static method with the same signature in the subclass though? Or is that forbidden as well?
a
I don't think (or may probably be wrong) but you can't access private anyway with static functions like main.
l
Yeah you can!
t
yes you can
a
Ohh
l
The static method is still a method of the class so it can access members that the class can access just fine!
t
but kotlin does not have static methods per se, if that is where you are going
l
I'm just trying to put a main method inside my
object
and I get completely misleading error messages that do not help me at all!
Is there any way to do this or does the mere presence of a
main
in the superclass make it completely totally impossible?
t
will it work with extension function?
Copy code
object Main : PApplet() {}

fun Main.main(...)
l
Extension functions aren't real functions and don't actually exist inside the class, so you can't use them to run the application...
t
ah sorry, missed what the goal was
l
The best solution so far is to use a "runner" class to start up the other class, but is there any other way?
a
Working kotlin to kotlin
need to further investigate the problem uwu
l
Try putting the top main inside Test and not inside a companion object!
I think?
a
JvmStatics aren't allowed inside the classes
true I am getting the same message if I try to declare the Test in a java file
accidental override
l
Do you think this is a java interop issue? Like an actual bug?
I have to do my own testing real quick!
@Animesh Sahu I think companion objects are real objects and the static method is actually not inside Test but inside Test.Companion! So you're not reproducing it with Kotlin because Kotlin doesn't let you put the static inside Test!
I can't convince IntelliJ to decompile the .class as Java, so I can't be sure!
a
Not really, they are also present in the class declaration itself which calls the Compaion's main.
l
How'd you get it to decompile like that?
a
Tools -> Kotlin -> show kotlin bytecode -> decompile
l
So maybe this is a Java interop bug then?
a
java -> java works, kotlin -> kotlin works
so yeah might be a!
l
Yay we found a bug! Where should the report go?
a
Youtrack is way to go (iirc)
l
Uh, which one? Link?
Oh, found it!
a
l
Found it, silly! Can I use your images in the bug report?
a
🙂
Apparently it's already reported!
a
Don't know how but this works lol
hahah
l
Internal members might be different than normal members!
Yuuup!
The signature's different so no accidental override error!
a
they are public in JVM, just used to mark a kotlin based app to forbid its usage in another package
while behave same as public inside the java
l
None of that matters, the only thing that matters in this case is the signature is different!
a
Copy code
@Suppress("ACCIDENTAL_OVERRIDE")
also works in there as suggested by youtrack issue there I saw.
l
Wait, you can just suppress compiler errors and it will compile??
What sorcery is this?
🤣 2
a
Lol don't know, it didn't came to my mind I saw the issue you provided just now 😛
l
That is so cursed!