Difference between KOTLIN class and KOTLIN file in...
# android
u
Difference between KOTLIN class and KOTLIN file in android studio ?
v
You mean in the "New" dialog?
The first one adds
class Foo { }
as content, the second one not, if you for example only want to put extension function and properties in
u
Actually I used both in two different files And now the class icon is same like other KOTLIN classes but the file icon is different even I have a class inside it with file name
v
Not sure what you mean, can you show a screenshot with annotations?
u
PXL_20210225_095121358.MP.jpg
ChangePhoneValidateFrag is class CommentsFragment is file But both have classes with file name declared inside then how they look different
v
The second has something additional, for example extension functions or extension properties
Or another class
u
As I said in CommentsFragment a class named CommentsFragment is declared and nothing special just a fragment implementation
v
Are you sure there are not other classes, top-level functions, top-level properties, extension functions, extension properties, ...?
u
You can reproduce this Simply use New dialog and select new kotlin file then declare a class of file name in it so it will look different
v
No, works fine here. Granted I use IntelliJ, not AS, but AS is basically a customized IJ.
­čĹŹ 1
j
are you sure the spelling is the same between the file name and class name?
u
@Vampire after deleting these two variables the class icon changed to expected icon,
Copy code
private const val ARG_PARAM1 = "param1"
private const val ARG_PARAM2 = "param2"
I see these two variables are declared outside of class declaration and may be this change is reflected in file icon
v
Of course, "correct icon" is not right, "expected icon" probably is. It indeed is correct, that the file-like icon is shown if there is more than the class, like a second class as I showed or some other top-level declarations like properties, constants or functions. The class-like icon is only shown if the file only contains one class and that class is named ike the file.
108 Views