DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
11 Monitoring and Observability Tools for 2023
Learn more
  1. DZone
  2. Coding
  3. Java
  4. When Should You Jump? JSR 308. That's When.

When Should You Jump? JSR 308. That's When.

Michael Nygard user avatar by
Michael Nygard
·
May. 08, 08 · Interview
Like (0)
Save
Tweet
Share
13.33K Views

Join the DZone community and get the full member experience.

Join For Free

one of the frequently asked questions at the no fluff, just stuff expert panels boils down to, "when should i get off the java train?" there may be good money out there for the last living cobol programmer, but most of the java developers we see still have a lot of years left in their careers, too many to plan on riding java off into it's sunset.

most of the panelists talk about the long future ahead of java the platform, no matter what happens with java the language. reasonable. i also think that a young developer's best bet is to stick with the boy scout motto: be prepared. keep learning new languages and new programming paradigms. work in many different domains, styles, and architectures. that way, no matter what the future brings, the prepared developer can jump from one train to the next.

after today, i think i need to revise my usual answer.

when should a java developer jump to a new language? right after jsr 308 becomes part of the language.

beware: this stuff is like cthulu rising from the vasty deep. there's an internal logic here, but if you're not mentally prepared, it could strip away your sanity like a chill wind across a foggy moor. i promise that's the last hypergolic metaphor. besides, that was another post .

jsr 308 aims to bring java a more precise type system, and to make the type system arbitrarily extensible. i'll admit that i had no idea what that meant, either. fortunately, presenter and mit associate professor michael ernst gave us several examples to consider.

the expert group sees two problems that need to be addressed.

the first problem is a syntactic limitation with annotations today: they can only be applied to type declarations. so, for example, we can say:

@nonnull list<string> strings;

if the right annotation processor is loaded, this tells the compiler that strings will never be null. the compiler can then help us enforce that by warning on any assignment that could result in strings taking on a null value.

today, however, we cannot say:

@nonnull list<@nonnull string> strings;

this would mean that the variable strings will never take a null value, and that no list element it contains will be null.

consider another example:

@nonempty list<@nonnull string> strings = ...;

this is a list whose elements may not be null. the list itself will not be empty. the compiler---more specifically, an annotation processor used by the compiler---will help enforce this.

they would also add the ability to annotate method receivers:

void marshal(@readonly object jaxbelement, @mutable writer writer) @readonly { ... }

this tells the type system that jaxbelement will not be changed inside the method, that writer will be changed, and that executing marshal will not change the receiving object itself.

presumably, to enforce that final constraint, marshal would only be permitted to call other methods that the compiler could verify as consistent with @readonly . in other words, applying @readonly to one method will start to percolate through into other methods it calls.

the second problem the expert group addresses is more about semantics than syntax. the compiler keeps you from making obvious errors like:

int i = "jsr 308";

but, it doesn't prevent you from calling getvalue().tostring() when getvalue() could return null. more generally, there's no way to tell the compiler that a variable is not null, immutable, interned, or tainted.

their solution is to add a pluggable type system to the java compiler. you would be able to annotate types (both at declaration and at usage) with arbitrary type qualifiers. these would be statically carried through compilation and made available to pluggable processors. ernst showed us an example of a processor that can check and enforce not-null semantics. (available for download from the link above.) in a sample source code base (of approximately 5,000 loc) the team added 35 not-null annotations and suppressed 4 warnings to uncover 8 latent nullpointerexception bugs.

significantly, findbugs, jlint, and pmd all missed those errors, because none of them include an inferencer that could trace all usages of the annotated types.

that all sounds good, right? put the compiler to work. let it do the tedious work tracing the extended semantics and checking them against the source code.

why the lovecraftian gibbering, then?

every language has a complexity budget . java blew through it with generics in java 5. now, seriously, take another look at this:

@notempty list<@nonnull string> strings = new arraylist<@nonnull string>();

does that even look like java? that complexity budget is just a dim smudge in our rear-view mirror here. we're so busy keeping the compiler happy here, we'll completely forget what our actual project it.

all this is coming at exactly the worst possible time for java the language. the community is really, really excited about dynamic languages now. instead of those contortions, we could just say:

var strings = ["one", "two"];

now seriously, which one would you rather write? true, the dynamic version doesn't let me enlist the compiler's aid for enforcement. true, i do need many more unit tests with the dynamic code. still, i'd prefer that "low ceremony" approach to the mouthful of formalism above.

so, getting back to that mainstream java developer... it looks like there are only two choices: more dynamic or more static. more formal and strict, or more loosey-goosey and terse. jsr 308 will absolutely accelerate this polarization.

and, by the way, in case you were thinking that java the language might start to follow the community move toward dynamic languages, alex buckley, sun's spec lead for the java language, gave us the answer today.

he said, "don't look for any 'var' keywords in java."

Java (programming language) Type system

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Test Execution Tutorial: A Comprehensive Guide With Examples and Best Practices
  • FIFO vs. LIFO: Which Queueing Strategy Is Better for Availability and Latency?
  • High-Performance Analytics for the Data Lakehouse
  • How To Set Up and Run Cypress Test Cases in CI/CD TeamCity

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: