Any
is a data-type , just like Int
or String
, but different from them.
Tuple
is a container, which can hold multiple data-types, i.e. it can contain vals of different data-types, but the type of the Tuple
will depend upon how many elements are there in the Tuple
, so for example:
val tup = (1, "hello", 4.4) // type of tup here is scala.Tuple3 (Int, String, Double)
val tup = (2.3, null) // type of tup here is scala.Tuple2 (Double, Null)
val tup = (5:Any, "hello", 2.2) // type of tup here is scala.Tuple3 (Any, String, Double)
But the type of each of the elements in the Tuple
will be maintained. Any
on the other hand, is like a homegenous data-type in which there's no unique type identity of the elements, be it a String
or Int
or Null
type initially, will be converted to a single data-type Any
and will lose all type-information.
Update:
The difference between a Tuple
and a List[Any]
is that a Tuple
can hold elements of multiple data types, still maintaining the data type of the individual elements.
While a List
or Array
can only hold elements of a single data type, so a List[Any]
will consist of all elements of type Any
, so it'll basically convert all the elements (irrespective of their earlier data-type) to Any
.