# Correct use of delegation?

**URL:** <https://discuss.kotlinlang.org/t/correct-use-of-delegation/2933>\
**Category:** Support\
**Created:** [May 27, 2017, 10:59am UTC](https://discuss.kotlinlang.org/t/correct-use-of-delegation/2933 "2017-05-27T10:59:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nangpa](https://avatars.discourse-cdn.com/v4/letter/n/a6a055/32.png) [@nangpa](https://discuss.kotlinlang.org/u/nangpa)\
**Post date:** [May 27, 2017, 10:59am UTC](https://discuss.kotlinlang.org/t/correct-use-of-delegation/2933/1 "2017-05-27T10:59:38Z")

</div>

I’m in my first week of learning Kotlin. I’m using it to re-write my Prolog language implementation (I find writing a compiler for another language is a good way to learn a new language)

Is the following the best way of doing what I’m attempting?

class Clause(tokens:MutableList) : MutableList by tokens

fun newClause():Clause{  
val tokens : MutableList = mutableListOf()  
return Clause(tokens)  
}//----  
//+++++++++++++++++++++++++++++++++++++++++++++

class Clauses(listOfClauses:MutableList) : MutableList by listOfClauses

fun newClauses():Clauses{  
val clauses : MutableList = mutableListOf()  
return Clauses(clauses)  
}//----  
//+++++++++++++++++++++++++++++++++++++++++++++

val myClauses = newClauses()

---

<div class="post-metadata">

**Author:** ![nangpa](https://avatars.discourse-cdn.com/v4/letter/n/a6a055/32.png) [@nangpa](https://discuss.kotlinlang.org/u/nangpa)\
**Post date:** [May 27, 2017, 11:06am UTC](https://discuss.kotlinlang.org/t/correct-use-of-delegation/2933/2 "2017-05-27T11:06:27Z")

</div>

Whoops! Didn’t spot the need for special treatment of \> and \<

Here;'s another attempt to post the code, using ‘preformatted’:

class Clause(tokens:MutableList`<Token>`) : MutableList`<Token>` by tokens

fun newClause():Clause{  
val tokens : MutableList`<Token>` = mutableListOf()  
return Clause(tokens)  
}//----  
//+++++++++++++++++++++++++++++++++++++++++++++

class Clauses(listOfClauses:MutableList`<Clause>`) : MutableList`<Clause>` by listOfClauses

fun newClauses():Clauses{  
val clauses : MutableList`<Clause>` = mutableListOf()  
return Clauses(clauses)  
}//----  
//+++++++++++++++++++++++++++++++++++++++++++++

val myClauses = newClauses()

---

<div class="post-metadata">

**Author:** ![nanodeath](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/nanodeath/32/1803_2.png) [@nanodeath](https://discuss.kotlinlang.org/u/nanodeath)\
**Post date:** [May 28, 2017, 3:48am UTC](https://discuss.kotlinlang.org/t/correct-use-of-delegation/2933/3 "2017-05-28T03:48:20Z")

</div>

It’s be a lot easier to read if you did:

````
```kotlin
<code>
```

````

to format your code.
