Last active
April 22, 2020 04:27
-
-
Save yenerm/a0d189d173665eb72b407e2d59689fe8 to your computer and use it in GitHub Desktop.
companion object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Copyright 2019 Google LLC. | |
SPDX-License-Identifier: Apache-2.0 --> | |
class SomeClass { | |
//… | |
companion object { | |
private var count: Int = 0 | |
fun count() { | |
count++ | |
} | |
} | |
} | |
class AnotherClass { | |
//… | |
companion object Counter { | |
private var count: Int = 0 | |
fun count() { | |
count++ | |
} | |
} | |
} | |
// usage without name | |
SomeClass.count() | |
// usage with name | |
AnotherClass.Counter.count() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment