Skip to content
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

Open
scabug opened this issue May 14, 2011 · 13 comments
Open

Support @static annotation to create static fields or methods. #4581

scabug opened this issue May 14, 2011 · 13 comments
Labels
Milestone

Comments

@scabug
Copy link

@scabug scabug commented May 14, 2011

Having the @static annotation would fill one feature of the JVM not possible in Scala.

For practicality, it will help in these cases:

  1. Some libraries require a static field. In particular, the android SDK requires classes implementing the Parceable interface to have a CREATOR static field

  2. 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.

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented May 14, 2011

Imported From: https://issues.scala-lang.org/browse/SI-4581?orig=1
Reporter: Ittay Dror (ittayd)

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented May 14, 2011

@soc said:
I guess this would be better discussed on the mailing list first.

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented May 14, 2011

@paulp said:
The second reason is invalid; static forwarders are already generated for methods in objects. You're right that there's no way to create a static field. The history of such requests suggests the answer will be "write it in java."

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented May 15, 2011

Ittay Dror (ittayd) said:
Another area where @static will help is remove the SerialVersionUID annotation. Instead users will just write:

  @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).

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented May 15, 2011

Ittay Dror (ittayd) said:
BTW, the "write it in Java" argument can also be used for removing the @Native annotation...

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented May 17, 2011

@dragos said:
This needs more than a simple ticket. Please open a discussion on one of the mailing lists, and maybe followup when a clear course of action has emerged.

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Jul 13, 2012

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Jul 13, 2012

@axel22 said:
reopening, the @static methods functionality is pending.

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Aug 3, 2012

Chris Sachs (c9r) said:
I'm pleased to see the inclusion of the @static annotation in Scala 2.10.0-M6. I noticed that @static vals don't get marked final, which limits HotSpot optimizations and jeopardizes the fabric of the cosmos. Heads up!

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        
}
@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Aug 27, 2012

@axel22 said:
Final modifiers are now retained - fixed in: scala/scala#1201

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Mar 15, 2013

Erik Bruchez (ebruchez) said (edited on Mar 15, 2013 7:29:15 PM UTC):
For reference, it seems that this was reverted, see scala/scala#1340.

Should the issue be reopened?

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Nov 11, 2013

Benoit Sigoure (tsuna) said:
Re-opening since this has been reverted.

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Apr 15, 2016

@lrytz said (edited on Apr 15, 2016 7:09:43 AM UTC):
looking at the "History" tab, this ticket was closed accidentally. A new SIP is in https://github.com/scala/scala.github.com/pull/491/files, the implementation in dotty in lampepfl/dotty#1155

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.