Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!

Rob Spoor

Sheriff
+ Follow
since Oct 27, 2005
Rob likes ...
Chrome Eclipse IDE Java Windows
Forum Moderator
Rob Spoor currently moderates these forums:
Cows and Likes
Cows
Total received
87
In last 30 days
0
Total given
32
Likes
Total received
1384
Received in last 30 days
5
Total given
2236
Given in last 30 days
4
Forums and Threads
Scavenger Hunt
expand Rancher Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Rob Spoor

It sounds like a content type issue. Can you check Chrome's developer tools when you open them and check the content type header?
6 hours ago

Carey Brown wrote:


Collectors.joining is overloaded to take a prefix and postfix:
1 week ago
The problem is that both bread and gingerbread contain brea. What you seem to want is to use either whole words, or words ending with those. That means you need to use the word boundary - \b. Add that after and (if needed) before the current pattern. Note that your existing pattern needs to be enclosed with ( or (?: and ), otherwise the word boundaries will be part of the first and last "word".
1 week ago
I'd start by checking out Quartz.
1 week ago

Campbell Ritchie wrote:It is possible that Paths has a private nested class which implements Path; that will never be visible in the public API. You can find out quite a bit simply from the code I showed you to find the class name. I expect it will differ with the implementation. The class might also be in a separate package whose documentation is omitted from the published API. That allows the implementer to change the actual class without having to give notice.


Actually, Path is based on the concept of FileSystemProvider and FileSystem. A FileSystemProvider can be "injected" through the service loader mechanism. It can then return one or more FileSystem and/or Path instances. The get method from Paths that takes Strings will always use the default FileSystem, which uses the local file system. The overloaded method that takes a URI will lookup the appropriate FileSystemProvider based on the scheme, then let that return the actual Path instance. For example, if you use memory-fs, a URI that starts with mem: will return an in-memory Path.

This is all documented in Paths.
1 week ago

Stephan van Hulst wrote:For instance, you could make an implementation for Unix systems that doesn't allow backslashes as separators, or something completely different (for instance, there are file systems that don't have a hierarchical folder structure at all).


By default there are (at least) two Path implementations: one for the local file system, and one for files inside ZIP files. But because almost all of NIO.2 is based on interfaces (like JDBC), it's actually not that hard to write custom classes. For instance (shameless plug):
  • memory-fs that stores "files" in memory. Can be quite useful to prevent storing content in a temporary file just because a method expects a Path.
  • ftp-fs to access FTP(S) file systems as if they were local.
  • sftp-fs: likewise but for SFTP (SSH).
  • 1 week ago
    .classpath only works inside Eclipse. When you run your JAR outside of it the file has no meaning at all. Instead you should use META-INF/MANIFEST.MF to add a Class-Path entry: https://docs.oracle.com/javase/tutorial/deployment/jar/downman.html. Note that these dependencies cannot be located inside your JAR file, because the class loader won't be able to find them there. The best is to use a relative path, and ship the JARs with your own JAR inside a ZIP file. Make sure that you are allowed to though, some libraries may prohibit this.
    1 week ago
    I have never extended ResourceConfig on my @ApplicationPath classes. Instead I extended Application. This has method getProperties that you can override to add properties like these. I used that in the past to disable bean validation (ServerProperties.BV_FEATURE_DISABLE) (because we had our own handling of ConstraintViolationExceptions).
    1 week ago
    JavaScript files for web applications should go in src/main/webapp (or a sub folder that's not WEB-INF). Anywhere else and it will not be directly accessible by browsers.
    1 week ago

    John Dryden wrote:

    Rob Spoor wrote:It is. Type inference works based on the context provided when the object is created. Because of all the chained calls the compiler cannot link the untyped call to builder() and the typed call to put.



    Bad compiler .

    But then, how does the stream api do it? It does nothing other than that.


    The stream itself is typed from the start. It's harder to create an untyped stream than it is to create a typed stream.

    You could perhaps change builder to take the first entry, that would give the compiler the necessary information.



    Doesn't really work out for me.
    Then I would stick with explicitly specifying the generic type as you already found out:
    Definitely. The JPA spec itself mandates that this is possible. In fact, XML is the only way to override mappings defined in annotations (like the generator used for @GeneratedValue).

    Prasad Saya wrote:

    The above code works without any exception.


    Try changing the loop to this, so it will use different keys:

    Apparently HashMap will allow overwriting the same entry while iterating, just not adding new entries (or removing entries by not using the Iterator).
    2 weeks ago

    John Dryden wrote:Which makes it seem like the entire Builder was untyped when build() was called.


    It is. Type inference works based on the context provided when the object is created. Because of all the chained calls the compiler cannot link the untyped call to builder() and the typed call to put.

    You could perhaps change builder to take the first entry, that would give the compiler the necessary information.
    If you're willing to upgrade to Java 9 or 10 you can use the new factory methods:

    If not you can easily write similar utility methods yourself.