Reflection
Reflection in Klyn starts with type(...) and expands into metadata about members,
inheritance, annotations, generics, and more. This is especially useful for tooling, tests, and
framework-style code.
Type
import klyn.math
r = Rational(1, 3)
metadata = type(r)
print(metadata.name)
print(metadata.fullName)
metadata = type(Runnable)
assert metadata.isInterface
assert metadata.isAbstract
Reflection exposes whether a type is public, abstract, final, native, an interface, an enum, or an annotation.
metadata = type(Rational(1, 3))
attrs = metadata.getAttributes()
props = metadata.getProperties()
methods = metadata.getMethods()
You can inspect declared members, retrieve a member by name, and choose whether inherited members should be included.
metadata = type(List<Int>)
print(metadata.isGenericInstantiation)
print(metadata.genericParameterCount)
print(metadata.genericParameterNames())
metadata = type(klyn.annotations.Deprecated)
print(metadata.isAnnotation)
Reflection can also expose annotations attached to types and members, which is how test frameworks and metadata-driven tooling discover annotated declarations.