overriding

How to force derived class to call super method? (Like Android does)

 ̄綄美尐妖づ 提交于 2019-11-28 05:36:26
I was wondering, when creating new Activity classes and then overriding the onCreate() method, in eclipse I always get auto added: super.onCreate() . How does this happen? Is there a java keyword in the abstract or parent class that forces this? I don't know if it is illegal not to call the super class, but I remember in some methods that I got a exception thrown for not doing this. Is this also built-in into java? Can you use some keyword to do that? Or how is it done? Here's the source of Activity#onCreate() - it is almost all comments ( original - see line ~800 ): /** * Called when the

What's the best way to override a user agent CSS stylesheet rule that gives unordered-lists a 1em margin?

房东的猫 提交于 2019-11-28 04:44:41
I'm working on a web app that has a topBar similar to facebook's blue bar at the top. I have an unordered list within the div of that bar to list some items, like Inbox, Notifications, etc. The UL has a 1em margin as defined by the user agent stylesheet of my browser. This is a problem because it's pushing my topBar down 1em. How can I override this to make the border of the ul = 0? I've read that overriding user agent stylesheets is a bad idea so I'm curious to learn what is best to do. Thanks. EDIT: Here's the CSS file: body { margin:0px; padding:0px; } #topBar{ background-color:#CCCCCC;

overridden method does not throw exception

我怕爱的太早我们不能终老 提交于 2019-11-28 03:49:26
问题 I have a problem when compiling my code, I'm trying to make a method of a class throw an personalized exception, given some conditions. But at the time of compiling I get the message: Overridden method does not throw exception Here's the class and exception declaration: public class UNGraph implements Graph Graph is an interface with all the methods of UNGraph in it (the method getId() doesn't have the throws declaration on that script) After the constructor I create the exception (inside the

Overriding class constants vs properties

女生的网名这么多〃 提交于 2019-11-28 03:44:25
I would like to better understand why, in the scenario below, there is a difference in the way class constants are inherited vs. instance variables. <?php class ParentClass { const TEST = "ONE"; protected $test = "ONE"; public function showTest(){ echo self::TEST; echo $this->test; } } class ChildClass extends ParentClass { const TEST = "TWO"; protected $test = "TWO"; public function myTest(){ echo self::TEST; echo $this->test; } } $child = new ChildClass(); $child->myTest(); $child->showTest(); Output: TWO TWO ONE TWO In the code above, ChildClass does not have a showTest() method, so the

Overriding equals() & hashCode() in sub classes … considering super fields

二次信任 提交于 2019-11-28 03:26:53
Is there a specific rule on how Overriding equals() & hashCode() in sub classes considering super fields ?? knowing that there is many parameters : super fields are private/public , with/without getter ... For instance, Netbeans generated equals() & hashCode() will not consider the super fields ... and new HomoSapiens("M", "80", "1.80", "Cammeron", "VeryHot").equals( new HomoSapiens("F", "50", "1.50", "Cammeron", "VeryHot")) will return true :( public class Hominidae { public String gender; public String weight; public String height; public Hominidae(String gender, String weight, String height

Custom Class used as key in Dictionary but key not found

こ雲淡風輕ζ 提交于 2019-11-28 03:19:36
问题 I have a class, show below, which is used as a key in a Dictionary<ValuesAandB, string> I'm having issues when trying to find any key within this dictionary, it never finds it at all. As you can see, I have overridden Equals and GetHashCode . To look for the key I'm using ValuesAandB key = new ValuesAandB(A,B); if (DictionaryName.ContainsKey(key)) { ... } Is there anything else that I'm missing? Can anyone point out what I'm doing wrong? private class ValuesAandB { public string valueA;

Is it possible to overload operators in C?

青春壹個敷衍的年華 提交于 2019-11-28 03:13:23
问题 Is it possible to overload operators (such as operators of comparison) in C? If so, how do you do it? I did a quick search, but all I found was for C++, and what I want is for C. Anyone have any ideas? Edit1: The idea is: I have a struct, and I need to do a comparison (based on a member of the struct). And for this I would like to associate operators compared to my new "data type". Edit2: I am completely aware that I can do without the use of operator overloading, but was wondering if you can

override log4j configuration programmatically: file location for FileAppender

≯℡__Kan透↙ 提交于 2019-11-28 03:11:51
问题 is it possible to override the "File" property of an appender that has been configured in the log4j.properties without creating a new appender? And if so - how? This is the situation: I have two apenders, A1 is a ConsoleAppender and A2 is a FileAppender. A2's "File" points a generic error.log: log4j.appender.A2.File=error.csv This appender only logs error-level events or worse through log4j.appender.A2.Threshold=error . Now I want those errors to be written in different files depending on

Java Polymorphism

拜拜、爱过 提交于 2019-11-28 03:04:54
问题 This is a question just out of curiosity. I know that when we call a subclass object's overridden method by the reference of it's superclass, JVM gives importance to the type of object and not to type of reference. This is my simple code : class Animal { void eat() { System.out.println("Animal is eating..."); } } class Horse extends Animal { @Override void eat() { System.out.println("Horse is eating..."); } } public class PolymorphismTest { public static void main(String...args) { Animal a

When NOT to call super() method when overriding?

爷,独闯天下 提交于 2019-11-28 03:01:15
When I make my own Android custom class, I extend its native class. Then when I want to override the base method, I always call super() method, just like I always do in onCreate , onStop , etc. And I thought this is it, as from the very beginning Android team advised us to always call super on every method override. But, in many books I can see that developers, more experienced than myself, often omit calling super and I really doubt they do it as a lack of knowledge. For example, look at this basic SAX parser class where super is omitted in startElement , characters and endElement : public