lundi 20 février 2017

How to adjust string to correct input type of classOf in scala?

I want to remove the following import:

import my.package.version.class1

the reason is that I want to pass the version as a parameter so I can have the following options:

my.package.version1.class1
my.package.version2.class1
my.package.version3.class1

When I do it hard-coded like that it works

classOf[my.package.version1.class1].getPackage

But I need it to be a String type so I can append the version each time. val hh = "my.package."+versionParamater+".class1"

 classOf[hh].getPackage //THIS WONT WORK error: identifier expected but string literal found.

I also tried doing this and it didnt work as well:

 val pkg = Package.getPackage(" my.package.version1.class1");

can you please assist?





Aucun commentaire:

Enregistrer un commentaire