GithubHelp home page GithubHelp logo

methref's Introduction

Type-Safe Method References

Maximilian Scherr, 2014-

A prototype of a mini library for dynamically creating "type-safe" method references, i.e. method objects. Reflective method objects such as java.lang.reflect.Method as well as java.lang.invoke.MethodHandle already fullfill such a role but are not really type-safe. Java 8's lambda expressions are type-safe but static, i.e. do not allow the dynamic generation of references to methods whose name is not statically known.

The library relies on Guava's TypeTokens to provide a representation of meta-level (generic) type objects. Type safety in the library presented here means that no unchecked casts need to be performed by users. Method reference resolution fails fast (if it fails) and unless users use unchecked casts to tamper with the created object's static type, no type-related issues should occur after successful resolution. Of course, the extent of type safety relies on the proper usage of the library and Guava's TypeTokens.

Performance

Method invocation is sped up using dynamic code generation. Tentative experiments suggest that the performance is comparable with the untyped approaches.

It seems that the optimization of reflective method invocation has received quite a lot of attention in recent JVM versions so the difference to using this library is not very large. In the experiments such calls are initially slower and seem to be JIT-compiled and optimized in a different fashion than other method objects including method handles, e.g. calls involving primitive types are quite a bit faster after some point.

Dependencies

  • Javassist 3
  • Guava 18.0

Unfinished Business

  • Proper error handling (checked exceptions)
  • Experiments and tests
  • Extending parameter limit? Currently set to 32 parameters ...

methref's People

Contributors

scherr avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.