Reputation: 861
What is practical difference between
class person(val name: String, val weight: Int)
and
type person = (String,Int)
?
Upvotes: 2
Views: 270
Reputation: 5023
In this case, it means to compare a tuple with class person. From my understanding, there maybe no comparison. Probably this example should looks like this ?
class Person(val name: String, val weight: Int)
type P = Person
so P is just alias of Person in this case, nothing fancy.
I assume that you maybe little confused that what we gained if we use "type". From my knowledge, there are several scenarios which make the keyword "type" very useful.
trait Like { type T }
trait PersonLike extends Like { override type T = Person }
type T = (Int => Int) => (String => String)
Anyway, I am not sure this clarify your confusion.
Upvotes: 0
Reputation: 62835
Type aliases are just aliases. They're substituted (resolved) at compile time and do not exists further. As a result, there no way to reference them from, say, java code.
Upvotes: 1