Limitations of Closures

The way RTSJ implements and uses closures in the Java language has several limitations. Some limitations are related to local inner classes; those we have to live with. Some only apply to anonymous local inner classes. Those are a matter of choice. Sometimes anonymous classes are much easier to understand. Other times it is better to use named classes.

Readability

The standard recommendation is not to use anonymous inner classes with more than about six lines of code in them, but the RTSJ-style usage can safely be used for any amount of code. In general use of anonymous inner classes, once they get bigger than about six lines it is too easy to forget that the code is just a class definition and is passed elsewhere for ...

Get Real-Time Java™ Platform Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.