All frameworks
ANJUNAR / OPEN SOURCE

Scala Universe

A resolved view of JVM types, generics and annotations.

01

The idea

Scala Universe turns Java reflection into a structured model of resolved types. Inspect fields, methods, constructors, bean properties and annotations without losing the concrete types behind inherited generics.

02

What it does.

01

Resolved generic types

Inspect inherited members with type parameters resolved against the concrete subclass.

02

Unified members

Find fields, methods, constructors and parameters through one consistent type model.

03

Property introspection

Build bean or annotation-based property models for framework code.

03

Installation

Add to your project
libraryDependencies += "com.anjunar" %% "scala-universe" % "1.0.3"

Package: com.anjunar:scala-universe

04

Start building.

Resolve a JVM class with TypeResolver, then inspect its members or build a property model with BeanIntrospector.

Resolve inherited generic members

The method is declared with T, but the resolved return type is String for StringBox.

Source code
import com.anjunar.scala.universe.TypeResolver

abstract class Box[T] { def getValue: T }
class StringBox extends Box[String] {
  override def getValue: String = "hello"
}

val resolved = TypeResolver.resolve(classOf[StringBox])
val method = resolved.findMethod("getValue")
println(method.returnType.raw) // class java.lang.String

Inspect a bean property

The property model exposes its type and can read or update the underlying instance.

Source code
import com.anjunar.scala.universe.introspector.BeanIntrospector

class Person {
  private var firstName = "Ada"
  def getFirstName: String = firstName
  def setFirstName(value: String): Unit = firstName = value
}

val model = BeanIntrospector.createWithType(classOf[Person])
val property = model.findProperty("firstName")
val person = new Person
property.set(person, "Grace")
println(property.get(person)) // Grace
05

By design.

The resolved class model keeps generic substitutions attached to every member. Frameworks can work with concrete types instead of repeatedly interpreting raw reflection values.

Your next step

Make it part of your stack.

Built carefully with Scala JS UI.Imprint