Heat a non-stick kadhai over medium-low and add grated coconut, sugar, and cream. Mix them well till they are well combined. Continue to cook them while stirring continuously till the mixture turns yellowish golden in color and starts leaving the sides of the kadhai like in this picture.
Remove the kadhai from heat and add cardamom powder and confectioners sugar and mix well.
Grease a thali or a 9-inch square pan with ghee. Pour the mixture into the greased pan and spread it evenly.
Sprinkle finely chopped pistachios (if using) and let the coconut barfi set for an hour or so in the refrigerator. Slice the barfi into sixteen equal pieces.