Using private package classes in Scala repl

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Using private package classes in Scala repl

Salil Surendran
Hello,
   I have several classes that are marked as 

package com.salil.mypackage

private [mypackage] MyClass{

}


However, I would like to use them in a scala repl. I tried using paste: -raw with code like :

package com.salil.mypackage {
 val my = new MyClass()
}

but that fails with :
<console>:1: error: illegal start of definition

any way to access these classes in a repl?

--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Using private package classes in Scala repl

Richard Bradley
See http://stackoverflow.com/questions/42068129/access-package-private-method-in-scala-repl

On Sunday, February 26, 2017 at 8:05:59 AM UTC, Salil Surendran wrote:
Hello,
   I have several classes that are marked as 

package com.salil.mypackage

private [mypackage] MyClass{

}


However, I would like to use them in a scala repl. I tried using paste: -raw with code like :

package com.salil.mypackage {
 val my = new MyClass()
}

but that fails with :
<console>:1: error: illegal start of definition

any way to access these classes in a repl?

--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Using private package classes in Scala repl

Jasper-M
In reply to this post by Salil Surendran
The reason for the error is that you declared a val in the top level of the package. Only classes or objects can be defined at that level.
So you need to do something like this:

package com.salil.mypackage {
  object Testing {
    val my = new MyClass()
  }
}

Kind regards,
Jasper

Op zondag 26 februari 2017 09:05:59 UTC+1 schreef Salil Surendran:
Hello,
   I have several classes that are marked as 

package com.salil.mypackage

private [mypackage] MyClass{

}


However, I would like to use them in a scala repl. I tried using paste: -raw with code like :

package com.salil.mypackage {
 val my = new MyClass()
}

but that fails with :
<console>:1: error: illegal start of definition

any way to access these classes in a repl?

--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Using private package classes in Scala repl

Salil Surendran
This works for Scala 2.11 but not for scala 2.10. Anyway to make it work?

On Monday, 27 February 2017 02:17:15 UTC-8, Jasper-M wrote:
The reason for the error is that you declared a val in the top level of the package. Only classes or objects can be defined at that level.
So you need to do something like this:

package com.salil.mypackage {
  object Testing {
    val my = new MyClass()
  }
}

Kind regards,
Jasper

Op zondag 26 februari 2017 09:05:59 UTC+1 schreef Salil Surendran:
Hello,
   I have several classes that are marked as 

package com.salil.mypackage

private [mypackage] MyClass{

}


However, I would like to use them in a scala repl. I tried using paste: -raw with code like :

package com.salil.mypackage {
 val my = new MyClass()
}

but that fails with :
<console>:1: error: illegal start of definition

any way to access these classes in a repl?

--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Using private package classes in Scala repl

Jasper-M
Hi,

I don't think there is. I think ":paste -raw" didn't exist in the 2.10 REPL.

Kind regards,
Jasper

Op woensdag 1 maart 2017 01:20:20 UTC+1 schreef Salil Surendran:
This works for Scala 2.11 but not for scala 2.10. Anyway to make it work?

On Monday, 27 February 2017 02:17:15 UTC-8, Jasper-M wrote:
The reason for the error is that you declared a val in the top level of the package. Only classes or objects can be defined at that level.
So you need to do something like this:

package com.salil.mypackage {
  object Testing {
    val my = new MyClass()
  }
}

Kind regards,
Jasper

Op zondag 26 februari 2017 09:05:59 UTC+1 schreef Salil Surendran:
Hello,
   I have several classes that are marked as 

package com.salil.mypackage

private [mypackage] MyClass{

}


However, I would like to use them in a scala repl. I tried using paste: -raw with code like :

package com.salil.mypackage {
 val my = new MyClass()
}

but that fails with :
<console>:1: error: illegal start of definition

any way to access these classes in a repl?

--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.