Since Java 8 I can go from
xyz.foreach(e -> System.out.println(e));
I can do the following
xyz.foreach(System.out::println)
I saw this thread about how method references work, but the problem is this:
Error: (16, 63) ambiguous reference to overloaded definition,
both toJson methods in an IanesJsonHelper object of type (source: IanesServer) String
and the toJson method in an IanesJsonHelper object of type (success: Boolean) String
corresponds to the expected type Function [?, String]
val json = IanesJsonHelper.toJson(array,IanesJsonHelper.toJson _)
^
I have 3 functions named "toJSON"
def toJson(id: Int): String
and
def toJson(success: Boolean): String
and
def toJson(source: IanesServer): String
The last one is correct.
The function that I called in the error message above:
def toJson[T](source: Array[T], toJson: Function[T, String]): String
This is the corresponding code:
val array = new Array[IanesServer](1)
array(0) = new IanesServer(1, "http://localhost:4567/", "Test")
val json = IanesJsonHelper.toJson(array,IanesJsonHelper.toJson)
I do not understand what my error is:
- The array is of type IanesServer
- T in the calling method should be IanesServer (Array [IanesServer] → Array [T]
- - 2. T , T , Function [IanesServer, String] → [T, String]
-, , , ? , [?, String]. ?
:
, :
IanesJsonHelper.toJson[IanesServer](array,IanesJsonHelper.toJson)