Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 492 Vote(s) - 3.56 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Annotate interface function that must call super

#1
I'm creating interface and some function in it has a body.
It's required, that class that implements this interface must call super in overriding function before executing other code.
How can I do this?

interface Watcher {
fun funWithoutBody()

fun startWatching() {
//do some important stuff which must be called
}
}
Reply

#2
You could just make `startWatching` abstract and call it in another function. E.g.:

interface Watcher {
fun funWithoutBody()

fun userDefinedStartWatching()

fun startWatching() {
//insert code you'd normally want to be called when using super()
userDefinedStartWatching()
}
}
Reply

#3
Android Studio / IntelliJ IDEA does this sort of thing in some cases but it isn't done through annotations but through [code inspection][1].

e.g. `MissingSuperCall` is an [Android Lint Check][2] for which IntelliJ IDEA supports ([Integration with Android Lint tool in IntelliJ IDEA 11.1 | IntelliJ IDEA Blog][3]).

You can create your own custom inspection if you are using Android Studio or IntelliJ IDEA: [IntelliJ IDEA 2016.2 Help :: Creating Custom Inspections][4].


[1]:

[To see links please register here]

[2]:

[To see links please register here]

[3]:

[To see links please register here]

[4]:

[To see links please register here]

Reply

#4
I've accidentally found, what I was looking for. It's a `@CallSuper` annotation available in `androidx.annotation` package. [Docs][1]

> Use the @CallSuper annotation to validate that an overriding method
> calls the super implementation of the method. The following example
> annotates the onCreate() method to ensure that any overriding method
> implementations call super.onCreate():

@CallSuper
protected fun onCreate(savedInstanceState: Bundle?) {
}


[1]:

[To see links please register here]

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through