# Can type parameter appear only in where statement?

**URL:** https://discuss.kotlinlang.org/t/can-type-parameter-appear-only-in-where-statement/3361
**Category:** Support
**Created:** [June 16, 2017, 8:02pm UTC](https://discuss.kotlinlang.org/t/can-type-parameter-appear-only-in-where-statement/3361 "2017-06-16T20:02:56Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![guai](https://avatars.discourse-cdn.com/v4/letter/g/7ba0ec/32.png) [@guai](https://discuss.kotlinlang.org/u/guai)
#### Post date: [June 16, 2017, 8:02pm UTC](https://discuss.kotlinlang.org/t/can-type-parameter-appear-only-in-where-statement/3361/1 "2017-06-16T20:02:56Z")

</div>

In java I have a method:

```java
    	public <T extends Relay, F extends Function<String, T>> T make_relay(Class<F> clazz, String name, Consumer<F> block) {
    		F builder = clazz.getConstructor().newInstance();
    		block.accept(builder);
    		T relay = builder.apply(name);
    		relay.setPlugin(this);
    		register(name, relay);
    		return relay;
    	}

```

it is a dsl method which produces instances of some specific derived class that inherits interface `Relay`.  
I have a bunch of this builders, say `FooRelayDsl`, `BarRelayDsl`, etc  
This builders have their own sets of methods.  
So I pass this specific builder class into method `make_relay` along with name and a lambda block, that contans actual dsl method calls which parameterize the builder and then that builder being fired to produce an instance of `Relay`’s heir class.  
And it returns that created instance of `Relay`.

I can use it like this:

```kotlin
val foo: FooRelay = make_relay(FooRelayDsl::class.java, "some_name") { builder : FooRelayDsl ->
  builder.set_some_foo_callback { TODO() }
  builder.set_some_foo_variant("foo1")
}

```

Now I want to make kotlin’s `inline fun` to make it prettier.  
First attempt:

```kotlin

inline fun <T : Relay, reified F : java.util.function.Function<String, T>> RelayMaker.makeRelay(name: String, noinline block: (F) -> Unit): T {
	return this.make_relay(F::class.java, name, block)
}

```

but it requires two type params

```kotlin
val fooRelayInstance = makeRelay<FooRelay, FooRelayDsl>("name") { it.set_some_foo_variant("foo1") }

```

Second attempt:

```kotlin

inline fun <reified F : java.util.function.Function<String, T>> RelayMaker.makeRelay(name: String, noinline block: (F) -> Unit): T
    where T : Relay {
	return this.make_relay(F::class.java, name, block)
}

```

it does not work. it does not know what `T` is cause it appear only in where and inside other type declarations

Is it possible to have only one type param and make it work?

---

<div class="post-metadata">

### Author: ![ilya.gorbunov](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/ilya.gorbunov/32/1645_2.png) [@ilya.gorbunov](https://discuss.kotlinlang.org/u/ilya.gorbunov)
#### Post date: [July 7, 2017, 6:39pm UTC](https://discuss.kotlinlang.org/t/can-type-parameter-appear-only-in-where-statement/3361/2 "2017-07-07T18:39:55Z")

</div>

It seems that a similar feature is requested in [https://youtrack.jetbrains.com/issue/KT-17061](https://youtrack.jetbrains.com/issue/KT-17061)

---

<div class="post-metadata">

### Author: ![guai](https://avatars.discourse-cdn.com/v4/letter/g/7ba0ec/32.png) [@guai](https://discuss.kotlinlang.org/u/guai)
#### Post date: [July 7, 2017, 6:57pm UTC](https://discuss.kotlinlang.org/t/can-type-parameter-appear-only-in-where-statement/3361/3 "2017-07-07T18:57:52Z")

</div>

Yeah. Same request  
I made one too [https://youtrack.jetbrains.com/issue/KT-18888](https://youtrack.jetbrains.com/issue/KT-18888)  
@ilya.gorbunov, pls konnect those issues in the tracker. It seems I can’t do it myself
