• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

uses unchecked or unsafe operation... umm

 
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
While studying for my SCJP exam, I've started trying to create some classes which will work together to gather and compress files, then move them onto another machine.

I found much of this code on javaalmanac.com. I'm getting a strange error, telling me that I'm using unsafe or unchecked operations...

Who, me? What? Where!!??


package BackupClient;

import java.io.*;
import java.net.*;
import java.util.LinkedHashSet;

class Directory {

private LinkedHashSet lhs;

/** Creates a new instance of Directory */
protected LinkedHashSet Directory() {

lhs = new LinkedHashSet();
File dir = new File("c:\\");

visitAllDirsAndFiles(dir);
return lhs;
}


// Put all Files into lhs...
private void visitAllDirsAndFiles(File dir) {
lhs.add(dir);

if (dir.isDirectory()) {
String[] children = dir.list();
for (int i=0; i<children.length; i++) {
visitAllDirsAndFiles(new File(dir, children[i]));
} // for
} // if
} // visitAllDirsAndFiles

} // Directory

What am I doing wrong?

Marcus
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Gotta rush home, but I can tell you it's because you are not using Java 1.5 Generics!

Where? The LinkedHashSet thingie. Can use LinkedHashSet<File> to fix it, or go back to 1.4 of course.
[ January 11, 2005: Message edited by: Barry Gaunt ]
 
Did you ever grow anything in the garden of your mind? - Fred Rogers. Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic