scala - How to use members with default (package) or private access level in REPL? -
i trying add interactivity test/debug cycle, tried playing around classes scala repl. works great has disadvantage cannot access package- , private-level members, can tested unit test (if test in same package).
can "set" package "context" of scala repl?
i guess use reflection access members, that's typing defeat purpose of using repl in first place.
i assume class testing written in java have go out of way create package member in scala.
in short, it's not possible. each line in repl wrapped it's own package, won't allowed access package-only member other package. though there undocumented system property change default package name prefix used wrapping, package name still generated automatically incrementing number:
$ scala -xprint:parser -dscala.repl.naming.line=foo.line scala> val x = 1 [[syntax trees @ end of parser]]// scala source: <console> package foo.line1 { object $read extends scala.scalaobject { // snip ... object $iw extends scala.scalaobject { // snip ... object $iw extends scala.scalaobject { // snip ... val x = 1 } } }
assuming often, create file makes reflection easy use , load repl using :load
command.
Comments
Post a Comment