Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use a same package file for all sub-packages in scala

Tags:

package

scala

I have a package object with some implicit classes in a package say x. Lets call it being in a file x.scala. I have two subpackages x.a and x.b. I need to use the same implicit classes in the two subpackages as well. As of now I have made package objects for the two subpackages in: a.scala and b.scala and replicated the code for the implicit class in the two objects. There must be a way this can be done in a better manner. Can I somehow use the package object of x package and use it in the two subpackages?

like image 986
Core_Dumped Avatar asked Mar 19 '23 05:03

Core_Dumped


1 Answers

Declare packages a and b like this:

package x
package a

and

package x
package b

This is sorta like saying package x.a followed by import x. Then you should have access to all of your implicit stuff in x.

like image 190
joescii Avatar answered Mar 21 '23 18:03

joescii