Answer the previous article.
1. Is there also a syntax for declaring upper bound and Lower Boud in Java? Some, such as:
List<e extends numeric> list<e Upper integer>
What is the difference between list<?> and list<object> in 2.Java?
List<?> represents any type of list that can be assigned to it
List<object> represents the type of element in list is arbitrary
Package Tstge;import java.util.*;p ublic class Tst {public static void main (string[] args) {arraylist<?> Mylist1 = null; Arraylist<object> mylist2 = null; arraylist<integer> mylist3 = new arraylist<integer> (); Mylist2 = Mylist3; error! Type Mismatch:cannot convert from arraylist<integer> to arraylist<object> mylist1 = Mylist3; }}
The type of 3.Java can usually be translated directly into the Scala type. But like Iterator<?> iterator< Extends component> such a type how to translate it?
Iterator[t] Forsome {type T} or Iterator[_]
Iterator[t] Forsome {type T <: Component}
About Forsome,stack overflow has a very good introduction:
Http://stackoverflow.com/questions/15186520/scala-any-vs-underscore-in-generics
4.View bound
def foo[a <% B] (x:a) = X
This means that where you call the Foo method, you must be able to see the conversion function from type A to type B, which is equivalent to
def Foo[a] (x:a) (implicit $ev 0:a = B) = X
5. Context bound
def Foo[a:b] (x:a) = X
TheFooMethod defines a constraintA:b. This constraint means the parameter
Xis of typeAa nd there must is an implicit value b[a] available when calling method
foo. Context bounds can be rewritten as follows
def Foo[a] (x:a) (implicit $ev 0:b[a]) = X
The current context must have an implicit Val of type b[a]
Scala in Depth 6 Scala type system