Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do I get the message: redundant overriding method?

This is not really an issue as much as I don't understand it. I'm just learning about Android Studio and Kotlin and am doing an online course in it. As instructed I used:

override fun onStart() {
   super.onStart()
}

However I get a message saying the override method is redundant and it grays out override fun as if it's a comment.

In the course video that doesn't happen. I assume it's some new feature of Kotlin and for some reson override fun does not need to be written anymore but can't find the answer online. Can anyone explain please?

This is the message I receive.

Redundant overriding method less... (Ctrl+F1)

Inspection info: This inspection reports redundant override modifiers which can be omitted.

like image 771
Neža Vižintin Avatar asked Jul 05 '19 17:07

Neža Vižintin


People also ask

What is method overriding in Android?

Method overriding is also called as Run time Polymorphism or Dynamic Binding. It increases the readability of code. It helps classes to be more specific in nature. Final and Static methods cannot be overridden.

What is overriding in java?

In Java, method overriding occurs when a subclass (child class) has the same method as the parent class. In other words, method overriding occurs when a subclass provides a particular implementation of a method declared by one of its parent classes.

How to report redundant overriding method less in a class?

Redundant overriding method less... (Ctrl+F1) Inspection info: This inspection reports redundant override modifiers which can be omitted. When you extend a class, you inherit all its methods.

Why do I keep getting redundant messages in outlook?

Incorrectly Rules: Sometimes when two or more “move a copy to” rules used to particular email also result in redundant messages in Outlook. Antivirus: Some of the third-party Antivirus software is also generating redundant messages in Outlook.

Why this method is overridden in Java?

So this method is overridden in order to return the values of the object which is showcased below via examples. Output Explanation: The output is the class name, then ‘at’ sign, and at the end hashCode of the object. All classes in Java inherit from the Object class, directly or indirectly (See point 1 of this ).

How to override a method in a class?

You could override them, but here, you override a method by just calling its super's implementation, which is redundant, since you can just call the same method without overriding it.


3 Answers

I had the same issue, when I started adding code to the function body the warning gone, I think you should add new code instead of just overriding onStart and its super method, also you can remove the whole function if you don't want to add code to it.

like image 51
Ziad Ahmad Avatar answered Oct 21 '22 09:10

Ziad Ahmad


When you extend a class, you inherit all its methods. You could override them, but here, you override a method by just calling its super's implementation, which is redundant, since you can just call the same method without overriding it.

like image 42
Mureinik Avatar answered Oct 21 '22 09:10

Mureinik


I see this warning whenever I override a method and then don't make any changes to it. It seems that the compiler is soooooo smart, that it say, "Hey stupid! That code is already written for you. So I'm going to flag it so that you know that I know that it's redundant. Aren't I smart?"

Show off. Too bad it's not smart enough to know that you are planning on making changes very soon.

like image 30
SMBiggs Avatar answered Oct 21 '22 07:10

SMBiggs