Should primitive types or non-primitive types be preferred in Java interfaces?

Posted by Greg Mattes on Stack Overflow See other posts from Stack Overflow or by Greg Mattes
Published on 2010-03-31T11:34:26Z Indexed on 2010/03/31 11:53 UTC
Read the original article Hit count: 394

Filed under:
|

(I thought I once read something about this in a book, but now I'm not sure where to find it. If this question reminds you of some material that you've read, please post a reference!)

What are the pros and the cons of primitives in interfaces?

In other words, is one of these preferable to the other and why? Perhaps one is preferable to the other in certain contexts?

public interface Foo {
    int getBar();
}

or

public interface Foo {
    Integer getBar();
}

Similarly:

public interface Boz {
    void someOperation(int parameter);
}

or

public interface Boz {
    void someOperation(Integer parameter);
}

Obviously there's the issue of having to deal with nulls in the non-primitive case, but are there deeper concerns?

© Stack Overflow or respective owner

Related posts about java

Related posts about interfaces