Skip to content
Anjunar/ DOCS

Scala Universe

A structured view of classes at runtime. Types are resolved once, generics are bound to the concrete subclass, and fields, methods and annotations share one model.

1.0.4Current release
JVMRuns on
Scala 3.3Language version
MITLicense

Installation

One artifact for the JVM. It brings Guava's TypeToken for generic resolution and the CDI API for the optional class path extension.

sbt
libraryDependencies += "com.anjunar" %% "scala-universe" % "1.0.4"

The generic type Java forgets

The field is declared as List[E] in the base class. Resolved through the subclass, it is a List[User].

scala
import com.anjunar.scala.universe.TypeResolver abstract class Repository[E] { var items: java.util.List[E] = new java.util.ArrayList[E]() } class UserRepository extends Repository[User] val repository = TypeResolver.resolve(classOf[UserRepository]) val items = repository.findField("items").fieldType println(items.name) // List println(items.typeArguments(0).name) // User
01 / Resolve

One model per type

TypeResolver turns any java.lang.reflect.Type into a cached ResolvedClass: raw class, type arguments and hierarchy.

02 / Bind

Generics seen from the subclass

Field types, return types and parameter types of inherited members are resolved against the type you started from.

03 / Describe

Properties instead of members

Bean and annotation introspectors join field, getter and setter into one property with the annotations of all three.

Where it is used

The type layer of json-mapper

json-mapper resolves every class through TypeResolver, reads @JsonbProperty members through AnnotationIntrospector and finds schemas through companionInstance. Anything that builds a framework on plain classes can do the same.

Contents

From a type to its properties

The type pages build the model, the member pages show what is in it, the introspection pages turn it into properties, and the practice pages put it to work.