Skip to content

Java derusting-ConnorH#26

Open
ConnorJohnHughes wants to merge 31 commits intoauberonedu:mainfrom
ConnorJohnHughes:main
Open

Java derusting-ConnorH#26
ConnorJohnHughes wants to merge 31 commits intoauberonedu:mainfrom
ConnorJohnHughes:main

Conversation

@ConnorJohnHughes
Copy link
Copy Markdown

No description provided.

Copy link
Copy Markdown
Owner

@auberonedu auberonedu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job! I really like your dedication to making lots of small commits, but we don't need quite this many. Probably no more than 2-3 commits per file would have been sufficient here, we don't need to commit after every single line changed.

Comment thread src/MapPractice.java
public static void main(String[] args) {
// Create a HashMap with String keys and Integer values and
// assign it to a variable of type Map
HashMap<String, Integer> map = new HashMap<>();
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and elsewhere, use interface types (List, Map, etc.) where appropriate.
For example:
List<String> strings = new ArrayList<>();
Note that the type on the left is List, not ArrayList. When we do this, we're more flexible to be able to change our code to use a different type of list later.

Similarly for maps:
Map<String, String> myMap = new HashMap<>();
Note that on the left we use Map instead of HashMap.

In summary:

  • interface type on left to declare type (List, Map, etc.)
  • Concrete type on right to instantiate instance (HashMap, ArrayList etc.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants