2

In scala, I can add to the end of list by,

val list = List[Integer](1,2,3,4)
val addEndList  = list:::List[Integer](101) //now this list has 1,2,3,4,101

I am trying to do it from java now,

scala.collection.immutable.List<Integer> list =  perform.getScalaListofSize(4); //1,2,3,4
scala.collection.immutable.List<Integer> list2 =  perform.getScalaListofSize(1); //1
scala.collection.immutable.List<Integer> list1 = list2.$colon$colon$colon(list);//1,2,3,4,1

Shouldn't the last line in java be:

list.$colon$colon$colon(list2)

its giving me output as

//1,1,2,3,4

1 Answer 1

5

Scala methods that end with : are right-associative when used with infix notation: If you do a ::: b in Scala it invokes b.:::(a). In your manual Java invocation you have to transpose the arguments yourself, as you discovered.

Sign up to request clarification or add additional context in comments.

2 Comments

Actually, he means methods. It's not a function, and Scala doesn't really have operators.
You might say "right-associative when used in infix notation".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.