0

I have a problem, because SuppressWarning("unchecked") doesnt work.

package com.example;

import javax.swing.*;
import java.awt.*;
import java.io.IOException;

import java.util.Dictionary;
import java.util.Hashtable;


public class Main {

    @SuppressWarnings("unchecked")
    public static void test(Dictionary test) {
        System.out.println(test);
    }

    public static void main(String[] args) throws IOException {
        Dictionary<Integer, Component> labelTable = new Hashtable<>();
        labelTable.put(1, new JLabel("text"));
        labelTable.put(2, new JLabel("text 2"));
        JSlider slider = new JSlider();

        slider.setLabelTable(labelTable);

        @SuppressWarnings("unchecked")
        Dictionary<Integer, Component> labelTable2 = slider.getLabelTable();
    }
}

shows this:

javac -Xlint com/example/Main.java
com/example/Main.java:14: warning: [rawtypes] found raw type: Dictionary
    public static void test(Dictionary test) {
                            ^
  missing type arguments for generic class Dictionary<K,V>
  where K,V are type-variables:
    K extends Object declared in class Dictionary
    V extends Object declared in class Dictionary
1 warning

Why it showed this warning after I had used @SuppressWarnings("unchecked")?

        @SuppressWarnings("unchecked")
        Dictionary<Integer, Component> labelTable2 = slider.getLabelTable();

This works..

  • 2
    That's a "rawtypes" warning. Use `@SuppressWarnings("rawtypes")`. Or better yet, [don't use raw types](https://stackoverflow.com/q/2770321/6395627). If you don't care about the actual type arguments, use `Dictionary, ?>`. – Slaw Mar 12 '23 at 19:09
  • Does this answer your question? [How to disable warning in Eclipse - 'Class is a raw type. References to generic type Class should be parameterized'](https://stackoverflow.com/questions/20949686/how-to-disable-warning-in-eclipse-class-is-a-raw-type-references-to-generic) – Ole V.V. Mar 12 '23 at 19:55

0 Answers0