java - Why use getResourceAsStream when loading images? -
let's i'm creating jar file , have icon in asset folder included in jar.
so before using, stage.geticons().add(icon);
in code there particular advantage or disadvantage having icon
image icon = new image("assets/icon.png");
vs.
image icon = new image(getclass().getresourceasstream("assets/icon.png"));
both seem work fine, i'm looking pinpoint should gravitate towards , why.
there's related topic here compares loading styles web applications.
javafx.scene.image(string)
calls validateurl
, additional processing of string
value, including checking current thread
s contextclassloader
resource.
the advantage of using class#getresourceasstring
you've made decisions class, (slightly) faster, less ambiguous , easier diagnose should have issues (as control source mechanism image itself) , aren't leaving decision making code don't control (and since validateurl
private static
, can't change)
Comments
Post a Comment