From oracle :
There may be times when you want to restrict the types that can be
used as type arguments in a parameterized type. For example, a method
that operates on numbers might only want to accept instances of Number
or its subclasses. This is what bounded type parameters are for.
Functionally, it is exactly the same thing since with a interface as parameter type, it might also only want to accept instances of Number or its subclasses.
Technically, it is slightly different since compiled classes should be different.
In your case, I would prefer use the raw interface type without wildcard since it's less verbose.
It doesn't mean that bounded type parameters in methods are useless.
It can indeed be useful when you use multiple bound type parameters.
Imagine that your method would accept a parameter at the condition that it belongs both to two specified types : InterfaceObj
and OtherInterfaceObj
.
With a interface type, to address this need, you should create another interface which extends these two interfaces and you would use it in your method such as :
public static void isTrue(boolean expression, MyTwoInterfacesObj interfaceobj) {
if (!expression) {
throw new RuntimeException();
}
}
With multiple bound type parameters, you don't need to create an additional interface. You can specify it such as :
public static <I extends InterfaceObj & OtherInterfaceObj> void isTrue(boolean expression, I interfaceobj) {
if (!expression) {
throw new RuntimeException();
}
}
With two interfaces, restricting the parameter type on both of them is a little awkward, imagine with three or four interfaces and multiple possible mixes of them.