Scala返回types的元组函数

我想做一个scala函数,它返回一个scala元组。

我可以做这样的function:

def foo = (1,"hello","world") 

这将工作得很好,但现在我想告诉编译器我期望从函数返回而不是使用内置types推断(毕竟,我不知道什么是(1,"hello","world")是)。

 def foo : (Int, String, String) = (1, "Hello", "World") 

编译器会将types(Int, String, String)Tuple3[Int, String, String]

另外,如果您厌倦了写入(Int,String,String),则可以创build一个types别名

 type HelloWorld = (Int,String,String) ... def foo : HelloWorld = (1, "Hello", "World") /// and even this is you want to make it more OOish def bar : HelloWorld = HelloWorld(1, "Hello", "World")