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
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 int getDayExpense2(WeekDay day) {
return switch (day) {
case SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY -> 100;
// case FRIDAY -> 200; // without using 'default', this line creates compile error
// case FRIDAY, SATURDAY -> 200 // valid
default -> 200; // valid
};
}
// We must use 'default' if we have int, String etc. common parameter type.
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();