# \[Java\] Generic type parameter declared with a final type bound

**URL:** <https://community.sonarsource.com/t/java-generic-type-parameter-declared-with-a-final-type-bound/3571>\
**Category:** New rules / language support\
**Tags:** java\
**Created:** [October 22, 2018, 4:27pm UTC](https://community.sonarsource.com/t/java-generic-type-parameter-declared-with-a-final-type-bound/3571 "2018-10-22T16:27:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![thw](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/thw/32/16105_2.png) [@thw](https://community.sonarsource.com/u/thw)\
**Post date:** [October 22, 2018, 4:27pm UTC](https://community.sonarsource.com/t/java-generic-type-parameter-declared-with-a-final-type-bound/3571/1 "2018-10-22T16:27:36Z")

</div>

**Description**  
Generic type parameters with final type bounds are not generic at all since there is just one possibility for the type parameter. Such generics should be refactored to work with the specific final type instead.

**Type**  
Code Smell

**Snippet**

```
public class GenericTypeParameterDeclaredWithAFinalTypeBound {

	public static <T extends String> T getStringGeneric() { // Noncompliant
		return null;
	}
	
	public static String getString() { // Compliant
		return null;
	}
	
}

```

**Note**  
Also covered by Eclipse JDT.

---

<div class="post-metadata">

**Author:** ![Alexandre\_Gigleux](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/alexandre_gigleux/32/26_2.png) [@Alexandre\_Gigleux](https://community.sonarsource.com/u/Alexandre_Gigleux)\
**Post date:** [October 30, 2018, 5:05pm UTC](https://community.sonarsource.com/t/java-generic-type-parameter-declared-with-a-final-type-bound/3571/3 "2018-10-30T17:05:22Z")

</div>

Hello,

Thanks for the suggestion.

Here is the specification [https://jira.sonarsource.com/browse/RSPEC-4968](https://jira.sonarsource.com/browse/RSPEC-4968) and the linked implementation ticket [https://jira.sonarsource.com/browse/SONARJAVA-2940](https://jira.sonarsource.com/browse/SONARJAVA-2940)

Regards
