List and Tuples in Scala

前端 未结 5 1914
温柔的废话
温柔的废话 2021-01-27 08:33

From the book \'Programming in Scala\' by Martin Odersky:

Another useful container object is the tuple. Like lists, tuples are immutable, but unlike lis

5条回答
  •  青春惊慌失措
    2021-01-27 08:48

    Just a note. If you get the Class Name of the List element, somehow Scala knows the type. Type inference maybe?

    scala> val l = List(1,2,3,"Adriano Avelar")
    val l: List[Any] = List(1, 2, 3, Adriano Avelar)
    
    scala> print(l(3).getClass.getSimpleName)
    String
    
    scala> print(l(2).getClass.getSimpleName)
    Integer
    
    

提交回复
热议问题