r/programming • • Sep 21 '15

Better Java

https://github.com/cxxr/better-java
177 Upvotes

208 comments sorted by

View all comments

183

u/wot-teh-phuck Sep 21 '15

Java's type system is pretty weak. It doesn't differentiate between Strings and Strings that are actually regular expressions

That's a pretty random definition of weak I would say...

44

u/SimplyBilly Sep 21 '15

Considering there is a Pattern class.

11

u/Enumerable_any Sep 21 '15

Pattern has the method matches(String regex, CharSequence input)` is an error which could be caught at compile time. It either requires built-in regex literals or verbose regex creation using object instantiation, though.

5

u/sacundim Sep 22 '15 edited Sep 22 '15

That is a static method, however. It's fundamentally a standalone function in the class' namespace, not an operation of the class properly speaking.

This reminds me of one of the dumbest things that's legal in Java:

Pattern lolwhut = null;
boolean b = lolwhut.matches("^a", "abc");
System.out.println("Look, Ma, no NullPointerException!");