From 604ec4a50d6b03147df433210afc6088ac43da97 Mon Sep 17 00:00:00 2001 From: Rob Winch Date: Thu, 11 Dec 2014 11:05:33 -0600 Subject: [PATCH] Session.getAttribute returns generic type This prevents the need to cast the attribute values. Fixes: gh-64 --- samples/users/src/main/java/sample/UserAccountsFilter.java | 2 +- .../src/main/java/org/springframework/session/Session.java | 3 ++- .../session/web/http/CookieHttpSessionStrategy.java | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/samples/users/src/main/java/sample/UserAccountsFilter.java b/samples/users/src/main/java/sample/UserAccountsFilter.java index 938ea27..a114ba4 100644 --- a/samples/users/src/main/java/sample/UserAccountsFilter.java +++ b/samples/users/src/main/java/sample/UserAccountsFilter.java @@ -63,7 +63,7 @@ public class UserAccountsFilter implements Filter { continue; } - String username = (String) session.getAttribute("username"); + String username = session.getAttribute("username"); if(username == null) { newSessionAlias = alias; continue; diff --git a/spring-session/src/main/java/org/springframework/session/Session.java b/spring-session/src/main/java/org/springframework/session/Session.java index d256be0..c6bc488 100644 --- a/spring-session/src/main/java/org/springframework/session/Session.java +++ b/spring-session/src/main/java/org/springframework/session/Session.java @@ -38,8 +38,9 @@ public interface Session { * * @param attributeName the name of the attribute to get * @return the Object associated with the specified name or null if no Object is associated to that name + * @param The return type of the attribute */ - Object getAttribute(String attributeName); + T getAttribute(String attributeName); /** * Gets the attribute names that have a value associated with it. Each value can be passed into {@link org.springframework.session.Session#getAttribute(String)} to obtain the attribute value. diff --git a/spring-session/src/main/java/org/springframework/session/web/http/CookieHttpSessionStrategy.java b/spring-session/src/main/java/org/springframework/session/web/http/CookieHttpSessionStrategy.java index aace52e..b93f3e0 100644 --- a/spring-session/src/main/java/org/springframework/session/web/http/CookieHttpSessionStrategy.java +++ b/spring-session/src/main/java/org/springframework/session/web/http/CookieHttpSessionStrategy.java @@ -121,7 +121,7 @@ import org.springframework.session.Session; * continue; * } * - * String username = (String) session.getAttribute("username"); + * String username = session.getAttribute("username"); * if(username == null) { * newSessionAlias = alias; * continue;