Skip to content
Advertisement

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

Advertisement