Learn Scala for Java Developers by Toby Weston

Learn Scala for Java Developers by Toby Weston

Author:Toby Weston [Weston, Toby]
Language: eng
Format: azw3, epub
Published: 2015-04-21T04:00:00+00:00


versus

val customers: List[Customer] = List() // scala

Creating a list in Scala like this also shows that it has the equivalent of the diamond operator. Scala’s type inference can work out that customers is of type Customer without repeating the generics on the right-hand side.

val customers: List[Customer] = List[Customer]() ^ // no need to repeat the type

Method Generics

You can define generic parameters for methods in a similar way. To define a generic parameter to a method without defining a generic type for the whole class, you’d do something like this in Java, where the generic type is defined straight after the public keyword and used as the type of the parameter a:

public <A> void add(A a) // java



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.