Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the concept and code of default methods in Java8 default methods

Shulou Source: shulou.com Published: 2022-06-03 11:14:02 09月14日 Update

< (slices + 1); i++) { Deck currentDeck = deckFactory(); currentDeck.addCards(dealtDeck.get(i)); mapToReturn.put(i, currentDeck); } return mapToReturn; } public String deckToString() { return this.entireDeck.stream().map(Card::toString) .collect(Collectors.joining("\n")); } public String toString(){ return deckToString(); } public static void main(String... args) { System.out.println("Creating deck:"); StandardDeck myDeck = new StandardDeck(); myDeck.sort(); System.out.println("Sorted deck"); System.out.println(myDeck.deckToString()); myDeck.shuffle(); myDeck.sort(new SortByRankThenSuit()); System.out.println("Sorted by rank, then by suit"); System.out.println(myDeck.deckToString()); myDeck.shuffle(); myDeck.sort(Comparator.comparing(Card::getRank).thenComparing( Comparator.comparing(Card::getSuit))); System.out.println("Sorted by rank, then by suit " + "with static and default methods"); System.out.println(myDeck.deckToString()); myDeck.sort(Comparator.comparing(Card::getRank).reversed() .thenComparing(Comparator.comparing(Card::getSuit).reversed())); System.out.println("Sorted by rank reversed, then by suit " + "with static and default methods"); System.out.println(myDeck.deckToString()); myDeck.shuffle(); myDeck.sort( (firstCard, secondCard) ->

FirstCard.getRank (). Value ()-secondCard.getRank (). Value (); System.out.println (myDeck.deckToString ()); myDeck.shuffle (); myDeck.sort (Comparator.comparing (Card::getRank)); System.out.println (myDeck.deckToString ()); Map map=myDeck.deal (4,11) For (Map.Entry item:map.entrySet ()) {System.out.println (item.getKey ()); System.out.println (item.getValue ()); System.out.println ("- -") } on the default method in Java8 default methods concept and code is shared here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Tags: Methods interfaces code poker cards functions versions concepts differences players static faceted conflicts binaries compatibility content variables dates times more Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Shulou Information macOS MariaDB NVidia