scala-newtype | NewTypes for Scala with no runtime overhead
kandi X-RAY | scala-newtype Summary
kandi X-RAY | scala-newtype Summary
NewTypes for Scala with no runtime overhead
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of scala-newtype
scala-newtype Key Features
scala-newtype Examples and Code Snippets
Community Discussions
Trending Discussions on scala-newtype
QUESTION
I am trying to use https://github.com/estatico/scala-newtype as follows:
...ANSWER
Answered 2020-Jun-20 at 19:07The README.md of scala-newtype says:
This expands into a type and companion object definition, so newtypes must be defined in an object or package object.
Macros are allowed to expand classes into other classes with the same name and companion objects, but from what I can tell, the newtype
annotation turns your case class
into an object of the same name (along with a type alias like type DbUrl = DbUrl.Type
). This behavior (turning a top-level annottee into a tree of some other kind) isn't allowed. If the annotation had generated a class DbUrl
, and maybe an object of the same name, though, it would have been all right, but pretty much anything else won't work.
To fix your problem, all you need to do is move this into a package object (or some other scope, as long as it isn't top-level).
Edit: As Dmytro Mitin pointed out, the created type is not the type of DbUrl
but rather something like type DbUrl = DbUrl.Type
with an uppercase "T", where the definition of DbUrl.Type
looks something like this (I'm just copying this from the README):
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install scala-newtype
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page