How can I refer to an instance field when writing documentation?
Consider this code:
object Foo {
val foo = 42
}
class Foo {
val foo = 42
}
In Java, one would use Foo.foo
for the "static" method and Foo#foo
for the instance method.
But in Scala #
is already taken for path-dependent types and
class Foo {
class foo
def foo = 42
}
is legal code, so I can't refer to it unambiguously.
Is there some convention how this should look like?
References to static methods A static method reference refers to a static method in a specific class. Its syntax is className::staticMethodName , where className identifies the class and staticMethodName identifies the static method.
Calling Instance Method: You can not call an instance method in the static method directly, so the Instance method can be invoked using an object of the class.
public class Example { int a = 10; // instance variable private static int b = 10; // static variable (belongs to the class) public void instanceMethod(){ a =a + 10; } public static void staticMethod(){ b = b + 10; } } void main(){ Example exmp = new Example(); exmp.
Tough. Maybe English-like, as in Foo's foo
? I had missed the ambiguity of #
. That is still my preferred choice, though, because the ambiguity only exists in the absence of context. When referring to a type, #
has one meaning. When referring to a value or method, #
has another.
Since types and methods/values do not share the namespace, I don't see the ambiguity being of relevance here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With