DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
View Events Video Library
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Integrating PostgreSQL Databases with ANF: Join this workshop to learn how to create a PostgreSQL server using Instaclustr’s managed service

Mobile Database Essentials: Assess data needs, storage requirements, and more when leveraging databases for cloud and edge applications.

Monitoring and Observability for LLMs: Datadog and Google Cloud discuss how to achieve optimal AI model performance.

Automated Testing: The latest on architecture, TDD, and the benefits of AI and low-code tools.

Related

  • Building a MongoDB-Powered RESTful Application With Quarkus and Eclipse JNoSQL
  • Eclipse JNoSQL 1.0.0: Streamlining Java and NoSQL Integration With New Features and Bug Fixes
  • Making A Good Thing Even Better: Google Open Source WindowBuilder and CodePro Profiler
  • How it Feels to Switch from Eclipse to Android Studio

Trending

  • DevSecOps: Integrating Security Into Your DevOps Workflow
  • The API-Centric Revolution: Decoding Data Integration in the Age of Microservices and Cloud Computing
  • Distributed Tracing Best Practices
  • How To Handle Technical Debt in Scrum
  1. DZone
  2. Coding
  3. Frameworks
  4. Get Warnings About Unused Method Arguments From Eclipse to Keep Code Clean

Get Warnings About Unused Method Arguments From Eclipse to Keep Code Clean

Byron M user avatar by
Byron M
·
Apr. 28, 10 · Interview
Like (1)
Save
Tweet
Share
18.66K Views

Join the DZone community and get the full member experience.

Join For Free

unused variables and methods should alway be unwelcome. removing them keeps the code cleaner and easier to read. now, by default eclipse warns you about unused private variables and methods, but it doesn’t warn you (by default) about unused method arguments.

but there is a compiler setting in eclipse that can warn you when you don’t use an argument in a method. you can even handle arguments on inherited methods, especially useful when using 3rd party libraries.

setup the compiler preferences

to get warnings of unused arguments:

  1. go to window > preferences > java > compiler > errors/warnings .
  2. open up the section unnecessary code .
  3. change the setting for parameter is never read from ignore to warning.
  4. (recommended, but optional) deselect ignore overriding and implementing methods . i recommend deselecting this option. you can leave it selected if you want to, but the feature loses a bit of its usefulness. i discuss this option a bit more in the next section.

here’s what the preference should look like:

and here’s an example of such a warning. in the example, the argument capacity isn’t used so is annotated as a warning.

what’s the easiest way to get rid of the warning? well, just remove the argument using the eclipse change method signature refactoring . this will remove the argument from the method declaration and any method callers in one go. however, if you can’t remove the argument from the method then read the next section.

on an old codebase you may get lots of warnings initially. i’d normally handle these on a class-by-class basis only for the classes i’m currently working on, unless the team has a specific cleanup project/task. just something to bear in mind, especially if you share workspace settings across the team via svn or similar.

what about method signatures that can’t be changed?

when you deselected ignore overriding and implementing methods, you told eclipse to warn you about unused arguments in implemented/overridden methods. it’s a good indicator that your superclass/interface method is passing in more than it needs to (ie. remove the argument from the method signature) or that you’re ignoring something important about the interface contract (ie. use it somewhere in your method).

but sometimes you can’t remove the argument because you don’t have control over inherited methods, especially if you implement/override a 3rd party library’s method or if the method is part of a bigger framework that’s difficult to change. other times you won’t have any need for the argument in very isolated cases. so you don’t want a warning to appear for these.

that’s why you can use the @suppresswarning compiler annotation to stop eclipse from reporting the warning. here’s an example:

public string process(@suppresswarnings("unused") int capacity, int max) {...}
you can apply suppresswarning to an individual argument or the whole method. i’d recommend annotating only the argument that you want to ignore.

eclipse makes it easy to add the compiler annotation. just navigate to the warning , press ctrl+1 and choose add @suppresswarning ‘unused’ to ‘variable’ (quick fix does its job again).

from http://eclipseone.wordpress.com/2010/04/27/get-warnings-about-unused-method-arguments-from-eclipse/

Eclipse

Opinions expressed by DZone contributors are their own.

Related

  • Building a MongoDB-Powered RESTful Application With Quarkus and Eclipse JNoSQL
  • Eclipse JNoSQL 1.0.0: Streamlining Java and NoSQL Integration With New Features and Bug Fixes
  • Making A Good Thing Even Better: Google Open Source WindowBuilder and CodePro Profiler
  • How it Feels to Switch from Eclipse to Android Studio

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: