7 Replies - 1302 Views - Last Post: 21 August 2011 - 07:38 AM Rate Topic: -----

#1 grimpirate   User is offline

  • Pirate King
  • member icon

Reputation: 149
  • View blog
  • Posts: 717
  • Joined: 03-August 06

Path and Paths interface generating odd compiler errors

Posted 20 August 2011 - 08:25 PM

I'm work with JDK 7 and attempting to make use of the new input/output. Here's the code:
import java.nio.file.Path;
import java.nio.file.Paths;

class MimeReader{
  public static void main(String[] args){
    if(args.length == 2){
      Path keyPath = Paths.get(args[0]).toRealPath(true);
      Path valuePath = Paths.get(args[1]).toRealPath(true);
    }else{
      System.out.println("Usage: MimeReader KEY VALUE");
    }
  }
}
And the following error is what the java compiler produces:

Quote

MimeReader.java:7: error: method toRealPath in interface Path cannot be applied to given types;
Path keyPath = Paths.get(args[0]).toRealPath(true);

required: LinkOption[]
found: boolean
reason: argument type boolean does not conform to vararg element type LinkOption


It also reproduces the same error for line 8. What I'm understanding here is that somehow it's interpreting a boolean value when in fact its seeking out a LinkOption[] value. However, if I understand the javadocs, Paths.get() method returns a Path, and I can use the toRealPath method to return another Path. So what am I missing here?

Is This A Good Question/Topic? 0
  • +

Replies To: Path and Paths interface generating odd compiler errors

#2 pbl   User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8381
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: Path and Paths interface generating odd compiler errors

Posted 20 August 2011 - 08:55 PM

arg[0] and arg[1] are String
the class String does not have a method toRealPath(boolean)

In which class did you find the method toRealPath() ?
Was This Post Helpful? 0
  • +
  • -

#3 grimpirate   User is offline

  • Pirate King
  • member icon

Reputation: 149
  • View blog
  • Posts: 717
  • Joined: 03-August 06

Re: Path and Paths interface generating odd compiler errors

Posted 20 August 2011 - 08:58 PM

This is the relevant javadoc:
http://download.orac....LinkOption...)
Was This Post Helpful? 0
  • +
  • -

#4 macosxnerd101   User is offline

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12800
  • View blog
  • Posts: 45,992
  • Joined: 27-December 08

Re: Path and Paths interface generating odd compiler errors

Posted 20 August 2011 - 09:04 PM

The toRealPath() method accepts a LinkOption[] param, not a boolean.
Path.get(args[0].toRealPath(new LinkOption[]{..LinkOption elements..});


Was This Post Helpful? 0
  • +
  • -

#5 pbl   User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8381
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: Path and Paths interface generating odd compiler errors

Posted 20 August 2011 - 09:11 PM

The relevant Javadoc says in the Path interface

Path toRealPath(LinkOption... options)

So any class that implements Path should provide a method toRealPath(LinkOption...) that returns a Path
As far as I know, unless they changed it in 1.7, String does not implement Path
Was This Post Helpful? 0
  • +
  • -

#6 macosxnerd101   User is offline

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12800
  • View blog
  • Posts: 45,992
  • Joined: 27-December 08

Re: Path and Paths interface generating odd compiler errors

Posted 20 August 2011 - 09:15 PM

Has nothing to do with String, except that Paths.get() accepts a String param. :)
Was This Post Helpful? 1
  • +
  • -

#7 pbl   User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8381
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: Path and Paths interface generating odd compiler errors

Posted 20 August 2011 - 09:19 PM

View Postmacosxnerd101, on 21 August 2011 - 12:15 AM, said:

Has nothing to do with String, except that Paths.get() accepts a String param. :)

Guess I will have to read 1.7 release notes
Was This Post Helpful? 0
  • +
  • -

#8 grimpirate   User is offline

  • Pirate King
  • member icon

Reputation: 149
  • View blog
  • Posts: 717
  • Joined: 03-August 06

Re: Path and Paths interface generating odd compiler errors

Posted 21 August 2011 - 07:38 AM

Hmm... somehow I glossed over that LinkOption parameter. However, why do the Java tutorials then say that a boolean is an acceptable value to pass to the function? Grotesque error?
http://download.orac...io/pathOps.html

@macosxnerd101: I understand the example you've given but how would I know what LinkOption elements to provide?

This post has been edited by grimpirate: 21 August 2011 - 07:56 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1