0

I was playing around with java interfaces a little and tried to implement a stack.
However, as soon as I added the constructor I got a compiler error:

./DefaultStack.java:5: error: <identifier> expected
DefaultStack<T> () {
                  ^

Here's my code:

public class DefaultStack<T> implements Stack<T> {
    DefaultStack<T> () {

    }
}

This is probably a really obvious mistake, but I'm kinda new to Java.

1 Answer 1

5

Remove <T> from the constructor's signature.Write constructor exactly the same way you wrote other methods

DefaultStack()
{

}

More Info :how to create a generic constructor for a generic class in java?

Sign up to request clarification or add additional context in comments.

1 Comment

I'll accept your answer in 5 minutes, feels like you can't do that within the first 15 mins of asking.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.