Skip to content

Instantly share code, notes, and snippets.

View nowshad-hasan's full-sized avatar
🎯
Focusing

Nowshad Hasan nowshad-hasan

🎯
Focusing
View GitHub Profile
// Which classes are permitted to extend this Liquid class, must be sealed/non-sealed/final.
public sealed class Liquid permits Water, Honey, Milk {}
// Now, Water can be extended by any class
public non-sealed class Water extends Liquid {}
// Honey is final. So, it can't be extended by anyone.
public final class Honey extends Liquid {}
// Milk is sealed. So, it starts another sealed hierarchy.
static void printBookOld(Book book) {
if (book instanceof Thriller) {
Thriller thriller = (Thriller) book; // must-do explicit casting
System.out.println(thriller.getSuspense());
} else if (book instanceof AutoBiography) {
AutoBiography biography = (AutoBiography) book; // must-do explicit casting
System.out.println(biography.getContribution());
}
}
public record NewStudent(String name, int age) {}
public class OldStudent{
private String name;
private int age;
public OldStudent(String name, int age) {
this.name = name;
this.age = age;
}
String newHtml = """
<html>
<head>
<title>
Hello Text Block
</title>
</head>
<body>
</body>
</html>
String oldHtml = "<html>\n" +
"<head>\n" +
" <title>\n" +
" Hello Text Block\n" +
" </title>\n" +
"</head>\n" +
"<body>\n" +
"</body>\n" +
"</html>";
private static void getDayStatus(WeekDay day) {
switch (day) {
case SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY -> System.out.println("On day");
case FRIDAY, SATURDAY -> System.out.println("Off day");
}
}
private static void getDayStatus(WeekDay day) {
switch(day) {
case SUNDAY:
case MONDAY:
case TUESDAY:
case WEDNESDAY:
case THURSDAY:
System.out.println("On day");
break;
case FRIDAY:
@nowshad-hasan
nowshad-hasan / vscode_shortcuts.md
Created April 30, 2021 08:03 — forked from bradtraversy/vscode_shortcuts.md
Helpful shortcuts for VSCode

VSCode Shortcuts

List of helpful shortcuts for faster coding

If you have any other helpful shortcuts, feel free to add in the comments of this gist :)

Official List of all commands

@nowshad-hasan
nowshad-hasan / PolymorphicMethodOverloading.java
Created April 5, 2021 16:11 — forked from ashikuzzaman-ar/PolymorphicMethodOverloading.java
Method overloading with polymorphic instances
public class PolymorphicMethodOverloading {
public static void main(String[] args) {
Consumer consumer = new Consumer();
Parent p1 = new Parent();
Parent p2 = new Child1();
Parent p3 = new Child2();
Child1 p4 = new Child1();
Child2 p5 = new Child2();