Guest User

Untitled

a guest
Feb 25th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. package com.example
  2.  
  3. import android.util.Log
  4.  
  5. class ClassA {
  6.  
  7. var iWantToUseThisFromTheInnerClass = "someValue"
  8.  
  9. fun runThisToStart() {
  10. val classB = ClassB(InnerClassA::class.java)
  11. classB.doSomething()
  12.  
  13. }
  14.  
  15. inner class InnerClassA(text: String) {
  16. init {
  17. Log.d("ClassA", "Constructor invoked " + text)
  18. }
  19. }
  20.  
  21. }
  22.  
  23. package com.example
  24.  
  25. import java.lang.reflect.InvocationTargetException
  26.  
  27. class ClassB<T>(private var mModelClass: Class<T>) {
  28.  
  29. val someText = "whatever"
  30.  
  31. fun doSomething():T {
  32. try {
  33. val constructor = mModelClass.getConstructor(String::class.java)
  34. return constructor.newInstance(someText)
  35. } catch (e: NoSuchMethodException) { // Throws this exception
  36. throw RuntimeException(e)
  37. } catch (e: InvocationTargetException) {
  38. throw RuntimeException(e)
  39. } catch (e: InstantiationException) {
  40. throw RuntimeException(e)
  41. } catch (e: IllegalAccessException) {
  42. throw RuntimeException(e)
  43. }
  44. }
  45.  
  46. }
Add Comment
Please, Sign In to add comment