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 ListWithTrash <T>( | |
private val innerList: MutableList<T> = ArrayList<T>() | |
) : MutableCollection<T> by innerList { | |
var deletedItem : T? = null | |
override fun remove(element: T): Boolean { | |
deletedItem = element | |
return innerList.remove(element) |
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 --> | |
Optional<String> opt = Optional.of("Java 8"); | |
if (opt.isPresent()){ //true | |
//... | |
} | |
opt = Optional.ofNullable(null); | |
if (opt.isEmpty()){ //true |
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 --> | |
import static java.util.Comparator.comparing; | |
comparing(Person::getFirstname).thenComparing(Person::getSurname); |
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 --> | |
List<person> list = Arrays.asList(personArray); | |
Stream<Person> stream1 = list.stream(); | |
//or | |
Stream<Person> stream2 = Stream.of(personArray); | |
//or |
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 → | |
LocalDate now = LocalDate.now(); | |
LocalDate androidBeta = LocalDate.of(2020, 6, 10); | |
Period period = Period.between(androidBeta, now); |
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 --> | |
ZoneOffset zoneOffSet= ZoneOffset.of("+03:00"); | |
OffsetDateTime offsetDateTime = OffsetDateTime.now(zoneOffSet); | |
System.out.println(offsetDateTime); | |
//2020-06-08T23:50:17.315+03:00 |
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 → | |
ZonedDateTime currentDate = ZonedDateTime.now(); | |
System.out.println("the current zone is "+ currentDate.getZone()); | |
//the current zone is America/Los_Angeles | |
ZoneId anotherZone = ZoneId.of(“Europe/Istanbul”); | |
ZonedDateTime currentDateInIstanbul = currentZone.withZoneSameInstant(anotherZone); | |
//2020-06-08T23:50:00.159+03:00[Europe/Istanbul] |
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
// Current date | |
LocalDate date = LocalDate.now(); | |
// Current time | |
LocalTime time = LocalTime.now(); | |
// Date of Android 11 beta launch | |
LocalDate date2 = LocalDate.of(2020, 6, 10); //yyyy,MM,dd |
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 --> | |
android { | |
defaultConfig { | |
//Only required when setting minSdkVersion to 20 or lower | |
multiDexEnabled true | |
} | |
compileOptions { |
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
fun <T> printType(classType: Class<T>) { | |
print(classType::class.java) | |
} |