简体   繁体   中英

Scala - Difference between parametric method and forSome

In Scala:

def rules[T]: Array[Rule[T]]= { ... }

vs.

def rules: Array[Rule[T]] forSome {type T} = { ... }

They are not the same because in some cases only the latter one is working.

forSome marks an existential type. Existential types may be used for client side type variance, which might be required for your use case. You can read more under this question.

What is the forSome keyword in Scala for?

or in the linked article

http://scalada.blogspot.de/2008/01/existential-types.html

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