Tobias Hermann
Tobias Hermann

Reputation: 10936

How to add a primary constructor to a generic class with type constraints?

Given the following minimal example:

interface IA
interface IB

class Foo1<T> where T : IA, T : IB {
    val x: Int
    constructor(x: Int) {
        this.x = x
    }
}

class Foo2<T>(val x: Int)

class Foo3<T> where T : IA, T : IB (val x: Int) // Error

Foo3 is a syntax error? What am I doing wrong?

Upvotes: 0

Views: 47

Answers (1)

Vindicar
Vindicar

Reputation: 511

In C# where clause comes after parameters.

class Foo3<T> (x: Int) where T : IA, T : IB

Upvotes: 2

Related Questions