Skip to content

Can't express sneakyThrow As Java #23922

@He-Pin

Description

@He-Pin

Compiler version

3.3.6

Minimized code

  @throws[T]
  def sneakyThrow[T <: Throwable, R](t: Throwable): R = {
    throw t.asInstanceOf[T]
  }

Output

[error] /Users/hepin/IdeaProjects/pekko/actor/src/main/scala/org/apache/pekko/japi/Throwables.scala:60:13: not found: type T
[error]     @throws[T]
[error]             ^

Expectation

Compiles as Java

    static <T extends Throwable, R> R sneakyThrow(Throwable t) throws T {
        throw (T) t;
    }

I can write :

  def sneakyThrow[T <: Throwable, R](t: Throwable): R = {
    throw t.asInstanceOf[T]
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions