1

For example: I want to declare an exception:

class UnexpectedEnumException(enum: Enum...) : Exception("Unexpected enum $enum")

In Java I can do this by

public class UnexpectedEnumException extends RuntimeException {

    public UnexpectedEnumException(Enum<?> en) {
        super("Unexpected enum " +  en);
    }
Jörg Vollmer
  • 198
  • 1
  • 7

1 Answers1

4

To expand on JB Nizet's comment, which should have been an answer, generics in Kotlin are a little bit different from Java. The usage of the star is explained in the Star projections section of documentation.

class UnexpectedEnumException(enum: Enum<*>)
    : Exception("Unexpected enum $enum")
Grzegorz Adam Hankiewicz
  • 7,349
  • 1
  • 36
  • 78