# Interop with third party Java libraries - threeten backport

**URL:** <https://discuss.kotlinlang.org/t/interop-with-third-party-java-libraries-threeten-backport/692>\
**Category:** Uncategorized\
**Created:** [December 2, 2013, 6:19am UTC](https://discuss.kotlinlang.org/t/interop-with-third-party-java-libraries-threeten-backport/692 "2013-12-02T06:19:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jonjanisch](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/jonjanisch/32/1578_2.png) [@jonjanisch](https://discuss.kotlinlang.org/u/jonjanisch)\
**Post date:** [December 2, 2013, 6:19am UTC](https://discuss.kotlinlang.org/t/interop-with-third-party-java-libraries-threeten-backport/692/1 "2013-12-02T06:19:47Z")

</div>

I'm using the ThreeTen Java 7 backport in my project ([http://threeten.github.io](http://threeten.github.io))

The API is beautiful but unfortunately it makes heavy use of factory methods that are not marked @NotNull.&nbsp;&nbsp;This makes the API very difficult to use with Kotlin.

For example:

&nbsp;&nbsp;fun hello() {  
 &nbsp;&nbsp;val today = LocalDate.now()  
  
   
 &nbsp;&nbsp;val tomorrow = today **.** plusDays(1)  
 &nbsp;&nbsp;}

Here, LocalDate.now() always return a non-null object, but unfortunately since this is a Java library the type of today is the nullable “LocalDate?”.&nbsp;&nbsp;So, today.plusDays is an error.&nbsp;&nbsp;I tried using LocalDate!!.now(), but IntelliJ marks this as an error as well: “LocalDate does not have a class object”.&nbsp;&nbsp;I realize now it was probably stupid of me to try using the !! here as it’s not an instance&nbsp;&nbsp;:) &nbsp;&nbsp;My temporary solution was to forcefully cast it as LocalDate:

&nbsp;&nbsp;fun hello() {  
 &nbsp;&nbsp;val today = LocalDate.now() as LocalDate  
  
   
 &nbsp;&nbsp;val tomorrow = today.plusDays(1)  
 &nbsp;&nbsp;}

…but this is not really a solution (tomorrow is still of type “LocalDate?” and casting here is probably a poor practice).&nbsp;&nbsp;The ThreeTen backport source code is on github, so I suppose I can fork it and add NotNull annotations.&nbsp;&nbsp;Is there an alternative approach I can use other than using the !! operator all over the place?

Thanks!

---

<div class="post-metadata">

**Author:** ![abreslav](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/abreslav/32/8279_2.png) [@abreslav](https://discuss.kotlinlang.org/u/abreslav)\
**Post date:** [December 2, 2013, 9:00am UTC](https://discuss.kotlinlang.org/t/interop-with-third-party-java-libraries-threeten-backport/692/2 "2013-12-02T09:00:39Z")

</div>

Instead of a cast, you can say

```kotlin
  fun hello() {
        val today = LocalDate.now()!!

        val tomorrow = today.plusDays(1)
  }
```

or

```kotlin

  fun hello() {
        val today = LocalDate.now()

  &nbsp;&nbsp;val tomorrow = today!!.plusDays(1)

  }
 
```

Also, consider using KAnnotator or annotating the factory methods as @NotNull using intentions in IntelliJ

---

<div class="post-metadata">

**Author:** ![jonjanisch](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/jonjanisch/32/1578_2.png) [@jonjanisch](https://discuss.kotlinlang.org/u/jonjanisch)\
**Post date:** [December 2, 2013, 3:15pm UTC](https://discuss.kotlinlang.org/t/interop-with-third-party-java-libraries-threeten-backport/692/3 "2013-12-02T15:15:38Z")

</div>

Thanks, I took a look at KAnnotator.&nbsp;&nbsp;It looks perfect, thanks.
