Regex magic for JAXB mappings

I am working on a project with 412 classes generated from a bunch of XSDs. This works well, but the names annoy me a bit. I don’t like most of the classes having names ending in Type, for example. A binding.xjb file solves the problem, but I didn’t want to write 412 <bindings> tags. Regular expressions […]

Multiple return types

Today I had this little problem: I have JMS messages with common properties, and some properties set depending on message type. I want to handle all the common properties in a specific method so I don’t need to duplicate code. How can I return different types from the same method!? Is this even possible in […]

Streaming Optional

The amazing Optional class in Java can sometimes be a bit frustrating; what if you have a bunch of them and want a nice and tidy Stream to do some work? If the “bunch” is a List or similar, then no problem. But what if not?

Callable and Supplier
– never shall the two meet!?

Let’s say we have this clever little legacy API method:

Now, we discover Java 8’s neat Supplier functional interface. As a courtesy to our users, we decide we would like to accept those as well. Does this work? A naïve addition gives us:

So far so good? Well, what happens if we try […]

A case for == on Class objects

Sending around Class objects can be useful in some cases. Most people don’t know or bother declaring them with types, and that can work too. I recently encountered code like this; the method choose was supposed to take Class objects belonging to a certain class hierarchy, and they used .equals() to find what class object […]

Ugly multiple inheritance in Java

Let’s say we have two classes:

Let’s imagine that the methods are really big and complex and for some horrid reason we want to inherit from both classes.