Skip to content

Commit cd40e8e

Browse files
committed
WIP
1 parent 2e47393 commit cd40e8e

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

sips/pending/_posts/2016-01-01-static-members.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ title: SIP 25 - @static fields and methods in Scala objects(SI-4581)
44
disqus: true
55
---
66

7-
__Dmitry Petrashko and Sébastien Doeraene__
7+
__Dmitry Petrashko, Sébastien Doeraene and Martin Odersky__
88

99
__first submitted TODO 2016__
1010

@@ -30,6 +30,7 @@ There is no special syntax proposed to access these members, they are accessed a
3030

3131
For example:
3232

33+
```scala
3334
{% highlight scala %}
3435
class Foo
3536

@@ -41,10 +42,12 @@ object Foo {
4142
println(Foo.x)
4243
println(Foo.bar(12))
4344
{% endhighlight %}
45+
```
4446

4547
Intuively, the presence of the `@static` annotation ensures that a field/method is declared as a static member of the companion class.
4648
For the JVM, the above would therefore look to other Java code as if it had been declared with the following Java code:
4749

50+
```java
4851
{% highlight java %}
4952
class Foo {
5053
public static int x = 5;
@@ -53,10 +56,12 @@ class Foo {
5356
}
5457
}
5558
{% endhighlight %}
59+
```
5660

5761
In Scala.js, the `@static` annotation has no semantic effect in Scala objects, as they are not visible from JavaScript anyway (it could be used for optimizations).
5862
It has a semantic effect on Scala.js-defined JS classes, for example:
5963

64+
```scala
6065
{% highlight scala %}
6166
@ScalaJSDefined
6267
class Foo extends js.Object
@@ -67,9 +72,11 @@ object Foo extends js.Object {
6772
@static def bar(y: Int): Int = x + y
6873
}
6974
{% endhighlight %}
75+
```
7076

7177
would look to JavaScript code as if it had been declared with the following JavaScript code:
7278

79+
```javascript
7380
{% highlight javascript %}
7481
class Foo extends Object {
7582
static bar(y) {
@@ -78,6 +85,7 @@ class Foo extends Object {
7885
}
7986
Foo.x = 5; // in ES6, there is no declarative syntax for static fields yet
8087
{% endhighlight %}
88+
```
8189

8290
## Restrictions ##
8391

0 commit comments

Comments
 (0)