You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: sips/pending/_posts/2016-01-11-static-members.md
+6-6Lines changed: 6 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -25,7 +25,7 @@ Static methods and fields for JavaScript classes are one of the very few things
25
25
26
26
## Overview ##
27
27
28
-
In order for method or field to be considered static it needs to be defined in an `object` and annotated `@static`.
28
+
In order for a method or field to be considered static it needs to be defined in an `object` and annotated `@static`.
29
29
There is no special syntax proposed to access these members, they are accessed as if they were a member of defining objects with all appropriate access requirements for accessing them.
30
30
31
31
For example:
@@ -44,7 +44,7 @@ println(Foo.bar(12))
44
44
{% endhighlight %}
45
45
```
46
46
47
-
Intuively, the presence of the `@static` annotation ensures that a field/method is declared as a static member of the companion class.
47
+
Intuitively, the presence of the `@static` annotation ensures that a field/method is declared as a static member of the companion class.
48
48
For the JVM, the above would therefore look to other Java code as if it had been declared with the following Java code:
49
49
50
50
```java
@@ -87,7 +87,7 @@ Foo.x = 5; // in ES6, there is no declarative syntax for static fields yet
87
87
{% endhighlight %}
88
88
```
89
89
90
-
## Comparisson with mirror classes ##
90
+
## Comparison with mirror classes ##
91
91
92
92
Scalac currently generates static forwarders for fields and methods in top-level objects:
93
93
@@ -108,7 +108,7 @@ If not annotated, it will be created in the companion module with a static forwa
108
108
109
109
## Restrictions ##
110
110
111
-
The following rules ensure that method can be correctly compiled into static member on both JVM and JavaScript:
111
+
The following rules ensure that methods can be correctly compiled into static members on both JVM and JavaScript:
112
112
113
113
1. Only objects can have members annotated with `@static`
114
114
@@ -130,14 +130,14 @@ If implemented in the dotty code base, the following modifications would be need
130
130
- extend `LambdaLift` to trigger an error if a method annotated with `@static` method cannot be lifted to the top level scope;
131
131
- extend `GenBCode` to emit static fields and methods in companion classes and forwarders to them in companion modules.
132
132
133
-
## Overriding&Hiding ##
133
+
## Overriding & Hiding ##
134
134
Java allows classes to define static methods with the same name and signature as a static method of a superclass. In order to define the semantics of such cases, the Java Specification introduces the notion of [hiding](http://docs.oracle.com/javase/specs/jls/se8/html/jls-8.html#jls-8.4.8.2).
135
135
136
136
This is required because in Java calling a `static` method on a class instance is supported.
137
137
This proposal does not need to introduce this notion as we do not support such calls.
138
138
139
139
## Comparison with [@lrytz's proposal](https://gist.github.com/lrytz/80f3141de8240f9629da) ##
140
-
Lucas Rytz has proposed a similar SIP, but his SIP requires changes to the typer to ensure that `@static` fields do not capture `this`, as in his proposal `@static` fields are defined in the class, rather than its companion object.
140
+
Lukas Rytz has proposed a similar SIP, but his SIP requires changes to the typer to ensure that `@static` fields do not capture `this`, as in his proposal `@static` fields are defined in the class, rather than its companion object.
141
141
It also does not address the question of `@static` members in inner objects and inheritance/hiding of those methods in subclasses.
0 commit comments