Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to refer to instance methods in documentation?

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?

like image 453
soc Avatar asked Aug 07 '11 13:08

soc


People also ask

How do you reference a static method?

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.

Can an instance method be called on an object?

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.

What are instance methods example?

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.


1 Answers

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.

like image 73
Daniel C. Sobral Avatar answered Sep 30 '22 16:09

Daniel C. Sobral