简体   繁体   中英

Scala: What does << mean?

I am very new to Scala. I have been asked to implement a feature so I am reading the codebase.

I see the following:

def * = (id ~: columns) <>(Account.<<.<<.<<.<<, (Account.unapply _).<<.<<.<<.<<)

...but I don't know what <<.<<. means, and Google did not gave me any correct result since it is a symbol.

What is this called?

<< is just a normal method name in Scala. It seems that in your code you have an Account object defined with a method name <<. And that method returns another object that also has method <<.

You need to look at the help or implementation of the Account.<< method to see what it does. There is nothing special in Scala regarding << that you should be concerned. It is all in your implementation.

将代码加载到IDE中(例如Scala IDE,Ensime或IDEA),并要求IDE转到该<<的定义。

I am not very familiar with Scala, but since it looks like an operator, a quick Google search on "Scala operators" gives the Scala Operator Cheat Sheet

This has the following on the << operator:

<< BigInt Leftshift of BigInt
<< Byte
<< Char
<< Int
<< Long
<< Short
<< Buffer Send a message to this scriptable object.
<< BufferProxy Send a message to this scriptable object.
<< Map Send a message to this scriptable object.
<< MapProxy Send a message to this scriptable object.
<< Scriptable Send a message to this scriptable object.
<< Set Send a message to this scriptable object.
<< SetProxy Send a message to this scriptable object.
<< SynchronizedBuffer Send a message to this scriptable object.
<< SynchronizedMap Send a message to this scriptable object.
<< SynchronizedSet Send a message to this scriptable object.

As for the . , I think that would be a way of chaining things.

Hence, one might be able to think of this as the << operator chained multiple times into Account etc.

However, << might actually be a method defined somewhere instead of one of the above operators.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM