Why can attributes in Java be public?

I think it’s possible because every rule has its exception, every best practice can be overridden in certain cases. For example, I often expose public static final data members as public (e.g., constants). I don’t think it’s harmful. I’ll point out that this situation is true in other languages besides Java: C++, C#, etc. Languages … Read more

Type-parameterized field of a generic class becomes invisible after upgrading to Java 7

This appears to be a javac6 bug, which is fixed in javac7. The workaround is by up-cast: ((Area<?>)area).parent = this; Which seems really odd – why would we need an up-cast to access a member in super class? The root problem is, private members are specifically excluded from inheritance, therefore A does not have a … Read more

Why can nested child classes access private members of their parent class, but grandchildren cannot?

Clever example! But it’s actually a somewhat boring explanation – there’s no visibility problem, you simply have no way of referring to t1 directly from T3 because super.super isn’t allowed. T2 can’t access its own t1 field directly since it’s private (and child classes don’t inherit their parent’s private fields), but super is effectively an … Read more

How to make a real private instance variable?

You can use the @private keyword inside the {} to make all subsequent variable declarations private. The default visibility is @protected (which is similar to protected in Java) and that generally works well. You’d have to specifically declare a variable as @public for it to be directly accessible outside the class. This Apple documentation has … Read more

How to apply -fvisibility option to symbols in static libraries?

Simply pass -Wl,–exclude-libs,ALL to gcc This will tell the linker to transform all the symbols in the static libraries to hidden. –exclude-libs also accepts a list of archives (i.e. static library names) for finer granularity on which libraries to hide symbols from. Note: this will only work in systems using GNU binutils (e.g. Linux) or … Read more

How to change visibility of layout programmatically

Have a look at View.setVisibility(View.GONE / View.VISIBLE / View.INVISIBLE). From the API docs: public void setVisibility(int visibility)     Since: API Level 1     Set the enabled state of this view.     Related XML Attributes: android:visibility Parameters: visibility     One of VISIBLE, INVISIBLE, or GONE. Note that LinearLayout is a ViewGroup which in turn is a View. That is, you … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)