# Objectype as function parameter

**URL:** <https://discuss.kotlinlang.org/t/objectype-as-function-parameter/20366>\
**Category:** Support\
**Created:** [December 26, 2020, 6:13pm UTC](https://discuss.kotlinlang.org/t/objectype-as-function-parameter/20366 "2020-12-26T18:13:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![felixgerdes](https://avatars.discourse-cdn.com/v4/letter/f/bbe5ce/32.png) [@felixgerdes](https://discuss.kotlinlang.org/u/felixgerdes)\
**Post date:** [December 26, 2020, 6:13pm UTC](https://discuss.kotlinlang.org/t/objectype-as-function-parameter/20366/1 "2020-12-26T18:13:31Z")

</div>

hello,

i’m just starting to work with kotlin. my first impressions are really good.

I’m trying to build some kind of store. Part of the store is an objecttype, which is part of the key. Technically is the store hold by an mutableMap.

The objecttype should by provided by an function parameter. But this is my problem. I’m looking for a possibility to only accept objects which are derived from an specific abstract class. Additionally this abstract class needs an generic parameter.

I try something like

```
fun add(aggrgegateType: Any<Aggregate<Any>>.....)

```

or with coherence

```
fun add(aggregateType: Aggregate<Any>......)

```

Do you have some input for my problems?

Thank you!

---

<div class="post-metadata">

**Author:** ![Wasabi375](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/wasabi375/32/4741_2.png) [@Wasabi375](https://discuss.kotlinlang.org/u/Wasabi375)\
**Post date:** [December 27, 2020, 12:06am UTC](https://discuss.kotlinlang.org/t/objectype-as-function-parameter/20366/2 "2020-12-27T00:06:51Z")

</div>

You could write something like

```auto
fun <T: Base> add(aggregateType: T)

```

That way you can only pass in objects that inherit from `Base`.  
You say that the abstract class has a generic parameter so this would look more like

```kotlin
fun <T: Base<Any>> add(aggregateType: T)

```

or if you need the generic parameter type for something else in the function

```auto
fun <P, T: Base<P>> add(aggregateType: T)

```

---

<div class="post-metadata">

**Author:** ![felixgerdes](https://avatars.discourse-cdn.com/v4/letter/f/bbe5ce/32.png) [@felixgerdes](https://discuss.kotlinlang.org/u/felixgerdes)\
**Post date:** [December 27, 2020, 9:52pm UTC](https://discuss.kotlinlang.org/t/objectype-as-function-parameter/20366/3 "2020-12-27T21:52:42Z")

</div>

Ah, thanks for your kind answer. It helps me a lot.  
In the end i struggled most with the an Any-Paramter.

In my opinen it is confusing that Any isn`t covariant automatically
