创建一个样例类来规范需要的数据
样例类实例化后会在多个类中进行使用,运行时也不需要改变值
构建其它类时基本上都需要这个参数
希望,例化其它类时不需要重复传入样例类的参数,能够直接在其它类中使用样例类的值
case class Platfrom(filePath: String,projectName: String)
class Test(platfrom:Platfrom) //构建其它的类基本上都需要使用到Platfrom
class Test1(platfrom:Platfrom)
class Test2(platfrom:Platfrom)
... //还需要很多类似的类
val platfrom = Platfrom("E:/Test/","test") //实例化样例类,参数由客户给出
val file = Test(platfrom)//怎么操作能不用重复传入实例化的样例类
val file1 = Test1(platfrom)//
val file2 = Test2(platfrom)//
...
请问是否有办法实现类似于全局变量类似作用的类,可以让需要的类直接使用,不用一直传参。
因为创建的其它类基本上都用得到这个参数。
或者是我实现的思路有问题? 是否有更好的方法来实现类似的功能。
样例类实例化后会在多个类中进行使用,运行时也不需要改变值
构建其它类时基本上都需要这个参数
希望,例化其它类时不需要重复传入样例类的参数,能够直接在其它类中使用样例类的值
case class Platfrom(filePath: String,projectName: String)
class Test(platfrom:Platfrom) //构建其它的类基本上都需要使用到Platfrom
class Test1(platfrom:Platfrom)
class Test2(platfrom:Platfrom)
... //还需要很多类似的类
val platfrom = Platfrom("E:/Test/","test") //实例化样例类,参数由客户给出
val file = Test(platfrom)//怎么操作能不用重复传入实例化的样例类
val file1 = Test1(platfrom)//
val file2 = Test2(platfrom)//
...
请问是否有办法实现类似于全局变量类似作用的类,可以让需要的类直接使用,不用一直传参。
因为创建的其它类基本上都用得到这个参数。
或者是我实现的思路有问题? 是否有更好的方法来实现类似的功能。