#Interfaces
1 messages · Page 1 of 1 (latest)
<@&987246399047479336> please have a look, thanks.
Here is an AI assisted attempt to answer your question 🤖. Maybe it helps! In any case, a human is on the way 👍. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.
t implements it, how do I do that in Java?
To achieve this in Java, you can define a method in your interface without providing an implementation. Each class that implements the interface will then provide its own implementation of the method, allowing it to return a different value based on the specific class.
Here is an example interface declaration:
public interface MyInterface {
public int myMethod();
}
And here is an example class implementing this interface with its own implementation of the method:
public class MyClass implements MyInterface {
@Override
public int myMethod() {
// Provide a unique implementation for this class
return 42;
}
}
You can have multiple classes implementing the same interface with their own unique implementations of the method. This way, each class can return a different value when calling myMethod().
I hope this helps! Let me know if you have any more questions about interfaces in Java.
^ this I understand how to override a method in a extended class but I want each class to inherit the function but the data type return will be different in every class that extends the interface
please lmk if im not making sense or being stupid
literally trying to make a get set function but not want to write it in every class
show your code please
By T you mean generics ? They should be fairly similar in java
class Foo<T> {
private final T value;
...
}
What does final do
similar to c# readonly
Ah okay Ty
but I want to create an interface that has a method in which takes a generic
as a parameter
yes, same