overriding

C# override public member and make it private

浪子不回头ぞ 提交于 2019-11-30 11:46:10
Possible? Can you change the access of anything to anything else? No, you can hide a public member with a private method in a subclass, but you cannot override a public member with a private one in a subclass. And, in actually, it's not just a public/private thing, this applies to narrowing the access in general. Revised : By hiding with a more restrictive access - in this case private access - you will still see the base class member from a base-class or sub-class reference, but it would defer to the new method when available from the new access level. So in general, when you hide, the hide

Override route helper methods

一世执手 提交于 2019-11-30 11:37:07
Question has many Comments. A URL "questions/123" shows a question. A URL: "questions/123#answer-345" shows a question and highlights an answer. 345 - is id of Answer model, "answer-345" is id attribute of HTML element. I need to override "answer_path(a)" method to get "questions/123#answer-345" instead of "answers/345" How to do it ? All url and path helper methods accept optional arguments. What you're looking for is the anchor argument: question_path(123, :anchor => "answer-345") It's documented in the URLHelper#link_to examples . Using this argument, you should be able to create an answer

Make sure base method gets called in C#

这一生的挚爱 提交于 2019-11-30 11:15:17
Can I somehow force a derived class to always call the overridden methods base? public class BaseClass { public virtual void Update() { if(condition) { throw new Exception("..."); // Prevent derived method to be called } } } And then in a derived class : public override void Update() { base.Update(); // Forced call // Do any work } I've searched and found a suggestion to use a non-virtual Update() but also a protected virtual UpdateEx(). It just doesn't feel very neat, isn't there any better way? I hope you get the question and I am sorry for any bad English. Use the template method pattern -

Invocation of a polymorphic field-like event

血红的双手。 提交于 2019-11-30 10:54:55
Considering the code below: public class TableMain { public virtual event Action UpdateFilter; .... } public class TableSub : TableMain { public override event Action UpdateFilter; public void UpdateQuery() { ..... if (UpdateFilter!=null) { UpdateFilter(); // Invocation of polymorphic field-like event??? } } } In this code ReSharper shows the alert "invocation of polymorphic field-like event". My question is: What does it actually mean? And is it an alert for a bad programming practice? Also, is it a bad practice to call an event polymorphically? (Knowing that an event can only be raised from

Bug with Override annotations in Eclipse

可紊 提交于 2019-11-30 10:45:51
I have a annoying problem with @Override annotations in Eclipse. Often when i import working projects on a new PC, Eclipse marks some of the @Override annotations as wrong. If i remove the annotations everything is fine and Eclipse also indicates that the methods are overriding the parents methods but adding the Override annotation causes the error again. I am currently working on an Android project so it might be a problem with Android and not with Eclipse.. Mark B This is most likely because you are switching between Java 1.5 and Java 1.6. In 1.5 you couldn't mark interface implementations

Why can't a class extend traits with method of the same signature?

风流意气都作罢 提交于 2019-11-30 10:26:37
问题 Why do I get the error below? How to workaround it? I assumed that since A and B compile to (interface,class) pairs, it's a matter of choosing the right static method call to implement when compiling C. I would expect the priority to be according to order. scala> trait A { def hi = println("A") } defined trait A scala> trait B { def hi = println("B") } defined trait B scala> class C extends B with A <console>:6: error: error overriding method hi in trait B of type => Unit; method hi in trait

Java - implementing multiple interfaces with same method and different return types

不羁的心 提交于 2019-11-30 10:19:54
Consider the following code: public interface A { public A another(); } public interface B { public B another(); } public interface AB extends A,B { public AB another(); } This leads to a compile error on AB : types B and A are incompatible; both define another(), but with unrelated return types I've seen this SO question , and follow the incompatibility example in the the accepted answer - i.e. public interface C { public void doSomething(); } public interface D { public boolean doSomething(); } public interface CD extends C,D { } However, in that case the return types were genuinely

More about Virtual / new…plus interfaces!

﹥>﹥吖頭↗ 提交于 2019-11-30 10:14:26
Yesterday I posted a question about the new/virtual/override keywords, and i learned a lot from your answers. But still i remain with some doubts. In between all the "boxes", i lost touch with what's really happening to the type's method tables. For instance: interface I1 { void Draw(); } interface I2 { void Draw(); } class A : I1, I2 { public void Minstance() { Console.WriteLine("A::MInstance"); } public virtual void Draw() { Console.WriteLine("A::Draw"); } void I2.Draw() { Console.WriteLine("A::I2.Draw"); } } class B : A, I1, I2 { public new virtual void Draw() { Console.WriteLine("B::Draw")

Android Linkify links textColor ignored, css style overrides possible?

牧云@^-^@ 提交于 2019-11-30 09:14:15
I am using Linkify in my app, and visited link text is appearing as dark purple. My overall layout background color is dark blue so this is impossible to read. The text is set as white, but visited links are appearing as dark purple. How do I override this? <TextView android:text="Website:" android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="14dip" android:paddingBottom="2dip" android:background="#ffffff" android:textColor="#577dbe" /> <TextView android:text="http://www.mysite.com/" android:layout_width="match_parent" android:layout_height="wrap_content"

Internal Workings of C# Virtual and Override

时光毁灭记忆、已成空白 提交于 2019-11-30 09:09:11
The topic of how C# virtual and override mechanism works internally has been discussed to death amongst the programmers... but after half an hour on google, I cannot find an answer to the following question (see below): Using a simple code: public class BaseClass { public virtual SayNo() { return "NO!!!"; } } public class SecondClass: BaseClass { public override SayNo() { return "No."; } } public class ThirdClass: SecondClass { public override SayNo() { return "No..."; } } class Program { static void Main() { ThirdClass thirdclass = new ThirdClass(); string a = thirdclass.SayNo(); // this