[Kotlin] MutableMap vs HashMap

문파이더맨·2021년 6월 18일
0

Kotlin

목록 보기
1/1
post-thumbnail

🔥 MutableMap vs HashMap 🔥

A mutable map is a map that is mutable. It's an interface. And it has plenty of implementstions (HashMap, TreeMap, ConcurrentHashMap, etc.). A HashMap is a specific implementation of a (Mutable)Map.

즉, MutableMap은 변경이 가능한 map 형태를 의미하고 interface에 속한다.
그 내부에는 많은 종류의 map이 있다. ex) HashMap, TreeMap, ConcurrentHashMap

고로, HashMap은 MutableMap의 한 종류일 뿐이다.


공식문서

📌 여기서도 알 수 있듯, MutableMap의 일환이다.

fun generateToken(email: String): String {
        val claims: MutableMap<String, Any> = HashMap()
        claims["email"] = email
        val now = Date()
        val expiryDate = Date(now.time + jwtExpirationInMs!!)
        return tokenPrefix + Jwts.builder()
                .setClaims(claims)
                .setIssuedAt(now)
                .setExpiration(expiryDate)
                .signWith(SignatureAlgorithm.HS256, jwtSecretKey)
                .compact()
}

val claims: mutableMap<String, Any> = HashMap()

  • 이 부분은 MutableMap은 interface라서 못 만들기 때문에 HashMap으로 만들어준다.
    -> HashMap은 구현체다.
profile
Sever 개발할래요.

0개의 댓글