1

I am trying to make a singleton fragment by doing this:

object MyFragment: BottomSheetDialogFragment {...}

But while building the project it gives compile time exception:

org.jetbrains.kotlin.codegen.CompilationException: Back-end (JVM) Internal error: Failed to generate expression: ktNameReferenceException

What is wrong with the above approach?

sak
  • 1,230
  • 18
  • 37
  • AFAIK fragments shouldn't be singletons [check](https://stackoverflow.com/questions/14839152/fragment-as-a-singleton-in-android) – Zain Dec 08 '21 at 06:48

1 Answers1

0
class MyFragment: BottomSheetDialogFragment() {

    companion object {
        val INSTANCE : MyFragment = ...
    }
}

But my questions is why do you need it? What problem are you trying to solve? It's a bit weird and unexpected approach I would say

Mike
  • 2,547
  • 3
  • 16
  • 30