I'd like my Scala program to be able to programmatically determine either its script filename or its class name, store the string in a variable program
and print out the name.
Java has several methods for this.
I'd like my Scala program to be able to programmatically determine either its script filename or its class name, store the string in a variable program
and print out the name.
Java has several methods for this.
Parsing the stack trace as hinted by 0__ should take care of most of the use cases, in particular when the object with the main method is not in a file of the same name:
Then you call this like that:
or you mix in into your main object
This works for scripts
scala A.script
whether the code is wrapped in an object or not. This also works when compiled withscalac
and run asscala A
. When run with the REPL, this will return<none>
.Rosetta Code
Not exactly sure what you are looking for...
gives me
And
gives me
I think this is the simplest: