I want to create a common service and common request as shown below: Then implement this service as shown below: However, although CompanyARequest is inherited from CommonRequest, createOrUpdate method throws “Method does not override method from its superclass” error. On the other hand, if I use generic for the request, the error is gone, but if I use generic for
Tag: interface
How can I implement interface correctly?
I am doing homework of making a simple calculator using java and interface in java. but the class that implements java gives error saying here is the code Answer There are a couple of issues here. First, since BasicCalculator is a public class, it needs to be defined in its own file named BasicCalculator.java. Second, the method names in BasicCalculator
Can you change the Type of Java Exception’s error message?
I’m writing an Internal-Facing tool with a very slow runtime. Because of this runtime I’m trying to validate the input for errors and send a JSON object with a detailed list of every missing or failing element to the client before actually running the tool. I was wondering if there was a way to modify java Exception’s error message return
Trying to mimic java functional interface
I am trying to mimic the java’s Function<T,R> by writing below code : when I am writing below code in andThen, it’s working fine (pointing to apply(T t) of interface) and perfectly chaining the other functional implementations But when writing below snippet, it’s falling into recursion, logically that’s correct , but why in snippet A, after.apply(apply(t)) is calling outer apply(T
What’s the meaning of this line of code? And how can I create an object of this class?
I was trying to construct an object of the MTree class (https://github.com/Waikato/moa/blob/master/moa/src/main/java/moa/clusterers/outliers/utils/mtree/MTree.java) The constructor of MTree looks like this: The DistanceFunction here is an interface, the code of it is: And it’s implementation is: And my first question is what’s the meaning of return new DistanceFunction<Data>() in the method public static <Data> DistanceFunction<Data> cached(final DistanceFunction<Data> distanceFunction) [the method is in
How to implement a generic interface that extends another generic interface in Java?
I am new to Java and working on implementing generic interfaces and that’s where I’d love some help. I want to implement a generic interface in Java that extends another interface. This is how the current interface structure looks like – I want to implement the ItemsProviderInterface interface and provide a definition for convertInput(), convertResponse(), request() methods. Maybe something like
Creating new instance of concrete implementation in interface – is this an antipattern?
Let’s say I have the interface AuthorDao with two different implementation classes for example MyAuthorDaoImpl1 and MyAuthorDaoImpl2. In my interface AuthorDao I have some basic crud methods and one extra method which is static for getting a new instance of MyAuthorDaoImpl1. It looks like this: Questions Is this static method getInstance() is not an anti-pattern? Because in my opinion we
Implementing List interface for CustomList in Java
I need to create a custom list that adds elements in pairs. I copied a similar implementation and adjusted it as needed, but unfortunately, it doesn’t work. And I have this for testing my code so far. The problem is that when I call add method the size of the list increases by 2 as it should, but nothing is
Define Methods in Interface Without Specifying Number of Parameters
I’m trying to implement classes from the same interface but with a different number of parameters in method like the code below. Is there a way in Java to define methods in the interface without constraining the number of parameters? Answer You could use the ellipsis syntax (…) and then check the number of arguments passed to the method in
How can I make classes implement an interface and print their methods based on a given parameter in Java?
I think this might be a very basic Java question, and I apologize since I’m a beginner, but I want to understand what am I getting wrong here: I’m supposed to create a package, and inside it, I must create the following: an interface with a method (the question says nothing besides it, so I created it empty) 2 classes,