-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support @static annotation to create static fields or methods. #4581
Comments
Imported From: https://issues.scala-lang.org/browse/SI-4581?orig=1 |
@soc said: |
@paulp said: |
Ittay Dror (ittayd) said: @static private val serialVersionUID = 432525L Writing it java is always an option... But having a module that has some files in Java and some in Scala sounds icky to me (esp. compilation of both). |
Ittay Dror (ittayd) said: |
@dragos said: |
@retronym said: |
@axel22 said: |
Chris Sachs (c9r) said: object Constants {
import scala.annotation.static
@static val Const: Int = 0 // should generate a static final field
@static final val FinalConst: Int = 0 // ditto
} public class Constants {
public static int Const;
public static int FinalConst;
public static {};
Code:
0: iconst_0
1: putstatic #11 // Field Const:I
4: iconst_0
5: putstatic #14 // Field FinalConst:I
8: return
public Constants();
Code:
0: aload_0
1: invokespecial #17 // Method java/lang/Object."<init>":()V
4: return
} |
@axel22 said: |
Erik Bruchez (ebruchez) said (edited on Mar 15, 2013 7:29:15 PM UTC): Should the issue be reopened? |
Benoit Sigoure (tsuna) said: |
@lrytz said (edited on Apr 15, 2016 7:09:43 AM UTC): |
link to Scala 3 SIP: https://docs.scala-lang.org/sips/static-members.html |
refs: Kotlin has a KEEP for static too Kotlin/KEEP#347 |
Having the @static annotation would fill one feature of the JVM not possible in Scala.
For practicality, it will help in these cases:
Some libraries require a static field. In particular, the android SDK requires classes implementing the Parceable interface to have a CREATOR static field
It will allow to create utility methods that are available "idiomatically" from Java code
I know that theoretically one can create a compiler plugin to do this. But there are few people that know how to do this.
The text was updated successfully, but these errors were encountered: