>can't override constructor on anonymous classI know it's stupid and trivial but goddamn if it doesn't piss me off. Is it because it'd look weird, having a class with no name override its constructor? It's such a pointless limitation.
Anyway writing more Java and working on irl projects makes me understand why it is the way it is for the most part. I still don't like the language as a whole, but I appreciate that its design goals are consistent and understandable, even if they're flawed.
For example, there's a point where you need to stop and realize that having anonymous functions would be a good thing. Option 1: pass a void anonymous function that takes no arguments. Option 2: create an interface specifically for void functions of no arguments, with a single method, then implement that interface wherever you want to use it.
It doesn't help that the syntax for doing trivial things feels verbose, either. The language just seems like it should only be written in some huge IDE that inserts boilerplate automatically.
(Sorry for complaining about the language in its discussion thread)
>>10576This works, but it's long. I'm only using it because pattern's split method destroys the pattern you supply as a delimiter, which is not what you want.
import java.util.*;
public class SplitCaps {
public static void main(String[] args) {
demo("Hello World");
demo("AbCdEfG");
demo("AbCdEfGh");
}
static void demo(String str) {
for(String s : splitcaps(str)) System.out.println('"' + s + '"');
System.out.println();
}
static ArrayList<String> splitcaps(String input) {
ArrayList<String> res = new ArrayList<String>();
StringBuffer str = new StringBuffer();
char c;
for(int i = 0; i < input.length(); i++) {
c = input.charAt(i);
if (Character.isUpperCase(c) && str.length() != 0) {
res.add(str.toString());
str.delete(0, str.length());
}
str.append(c);
}
if (str.length() != 0) res.add(str.toString());
return res;
}
}
/* program output:
"Hello "
"World"
"Ab"
"Cd"
"Ef"
"G"
"Ab"
"Cd"
"Ef"
"Gh"
*/