Monday, July 11, 2016

Consider:
{
public final byte VALUE1 = 0xF0;
public final byte VALUE2 = 0x10;
}

The highlighted part is an error. Really?

OK, Java developers aren't allowed to determine the size of a variable (they should just know that float is always 32-bits) but when initialising a byte to anything >127 (0x7F) Java thinks it's a negative number and therefore cannot be assigned to a byte. WTF, Java?

Come on.

Here is a workaround:
{
public final byte VALUE1 = (byte)0xF0;
}

Fucking Java...

Wednesday, July 6, 2016

Here is some code:

String s1 = "Hello";
String s2 = "World!";
String s3 = s1 + " " + s2;

If operator overloading is "so bad" that the developers shouldn't use it, why do you???

The above code should've been (which is also valid):

...
String s3 = s1.concat(" ").concat(s2);

WTF???

Tuesday, July 5, 2016

A great article about ViewPager and using it without fragments: https://www.bignerdranch.com/blog/viewpager-without-fragments/

public enum CustomPagerEnum {
 
    RED(R.string.red, R.layout.view_red),
    BLUE(R.string.blue, R.layout.view_blue),
    ORANGE(R.string.orange, R.layout.view_orange);
    

    private int mTitleResId;
    private int mLayoutResId;
 
    CustomPagerEnum(int titleResId, int layoutResId) {
        mTitleResId = titleResId;
        mLayoutResId = layoutResId;
    }
 
    public int getTitleResId() { return mTitleResId; }
    public int getLayoutResId() { return mLayoutResId; }
}


OK, What The FUCK, Java?????????????

Why is there a constructor, local variables, and methods (did I miss anything?) in a fucking enum???

Oh, wait, I did miss something (corollary of having a constructor): RED, BLUE, and ORANGE are not constant integral values like in any other language. How on Mother Earth is this an enum???

Why not just call it a class with public static final members???

StringBuilder sb=new StringBuilder();
sb.append("Data length: ").append(data != null ? data.length : "<null>").append("\n");

I understand that a StringBuilder object can append almost anything, but C# would've told me I'm an idiot for returning different types in a ternary operator...