Search Results

Search found 5671 results on 227 pages for 'final'.

Page 1/227 | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Naming convention: Final fields (not static)

    - by Zeeker
    Today I had a discussion with a co-worker about the naming of final fields in Java classes. In his opionion final fields should also be considered constants since their values won't change after the creation of the instance. This would lead to the following naming convention for final fields: public class Foo { private static final String BLA_BLA = "bla"; private final String BAR_BATZ; ... } In my opinion only static final fields should be considered constants while fields which are only final should follow the usual camelCase naming convention. public class Foo { private static final String BLA = "bla"; private final String barBatz; ... } Now I'm a bit uncertain since he is a far more experienced programmer than I am and I usually agree with his opinions and consider him a very good developer. Any input on this?

    Read the article

  • exporting clip in Final Cut Pro X or related video editing software on Mac

    - by user46976
    I'm using Final Cut Pro X to edit a 1 hour long video. I made individual clips from it in Final Cut Pro X and I want to save just these clips, some of which are only 5 mins long. How can I do this? I tried using the app ClipExporter, but it won't even read my .fcpxml file, it just says that it's not a valid file and gives no helpful information at all. Another method I tried was to assign roles to each clip. I made one clip, 5 mins long, and then used Share - Export in Final Cut Pro X and chose the option to export roles as separate files. However, the export still estimates that it will take over an hour to export and so it looks like it's trying to export the whole movie, rather than the simple 5 min clip which should be exportable as a .MOV or related formats in a few minutes. How can I do this in final cut pro x? I'm also happy to switch to related video editing software as long as they are not extremely expensive. This seems like a very trivial and obvious feature: take a segment from a long movie and export just the selected region of it... I don't understand why it's so complicated to do in Final Cut Pro X. Thanks.

    Read the article

  • Closest Ruby representation of a 'private static final' and 'public static final' class variable in

    - by Hosh
    Given the Java code below, what's the closest you could represent these two static final variables in a Ruby class? And, is it possible in Ruby to distinguish between private static and public static variables as there is in Java? public class DeviceController { ... private static final Device myPrivateDevice = Device.getDevice("mydevice"); public static final Device myPublicDevice = Device.getDevice("mydevice"); ... public static void main(String args[]) { ... } }

    Read the article

  • Why can final object be modified?

    - by Matt McCormick
    I came across the following code in a code base I am working on: public final class ConfigurationService { private static final ConfigurationService INSTANCE = new ConfigurationService(); private List providers; private ConfigurationService() { providers = new ArrayList(); } public static void addProvider(ConfigurationProvider provider) { INSTANCE.providers.add(provider); } ... INSTANCE is declared as final. Why can objects be added to INSTANCE? Shouldn't that invalidate the use of final. (It doesn't). I'm assuming the answer has to do something with pointers and memory but would like to know for sure.

    Read the article

  • Java method keyword "final" and its use

    - by Lukas Eder
    When I create complex type hierarchies (several levels, several types per level), I like to use the final keyword on methods implementing some interface declaration. An example: interface Garble { int zork(); } interface Gnarf extends Garble { /** * This is the same as calling {@link #zblah(0)} */ int zblah(); int zblah(int defaultZblah); } And then abstract class AbstractGarble implements Garble { @Override public final int zork() { ... } } abstract class AbstractGnarf extends AbstractGarble implements Gnarf { // Here I absolutely want to fix the default behaviour of zblah // No Gnarf shouldn't be allowed to set 1 as the default, for instance @Override public final int zblah() { return zblah(0); } // This method is not implemented here, but in a subclass @Override public abstract int zblah(int defaultZblah); } I do this for several reasons: It helps me develop the type hierarchy. When I add a class to the hierarchy, it is very clear, what methods I have to implement, and what methods I may not override (in case I forgot the details about the hierarchy) I think overriding concrete stuff is bad according to design principles and patterns, such as the template method pattern. I don't want other developers or my users do it. So the final keyword works perfectly for me. My question is: Why is it used so rarely in the wild? Can you show me some examples / reasons where final (in a similar case to mine) would be very bad?

    Read the article

  • About local Final varibles in java

    - by Sathish
    In java Program, parameters which is defined as String in method declaration.But in method definition it is accessed as final String variable. Whether it'll lead to some issues (like security, memory problem)? For Example: Method Declaration join(String a,String b); Method definition public void join(final String a,final String b) { Authenticator au = new Authenticator(){ public PasswordAuthentication getPasswordAuthentication(){ return new PasswordAuthentication(a,b)} }; } Please help for me and clarify my doubts. Thanks in advance P.S. I;m accessing a and b as final variable because i've to use it in the inner class.

    Read the article

  • Why this cache doesn't work using final as modifier

    - by Pentium10
    I have this code to get the Cursor once for this instance, and the Log shows it is called many times although I marked as final. What I am missing? private Cursor getAllContactsCached() { final Cursor c=this.getList(); return c; } getAllContactsCached method should retrieve list once, and the 2nd time it should reuse the final object for return

    Read the article

  • Trouble exporting quicktime movie in Final Cut Pro

    - by Kato
    I'm having a very strange problem exporting a sequence to quicktime in FCP6. I've never had this problem before. After the sequence is exported, the last 3 minutes play very choppy, and the last minute does not export at all! There is nothing unrendered there, and the first 10 minutes play perfectly. The only thing that is different about the last bit is that there are titles there, but the export goes wonky at least 2 minutes before that. I'm exporting using Apple Pro Res 422 HQ 1920x1080 30p, and the footage is from HMC150, shot in 1080p30. Any advice would be appreciated!

    Read the article

  • Set Final Cut Express Sequence Options to 970p30

    - by Maccaius
    Hi I have an project in FCE which was recorded in MPEG-4 video in 1280 x 960 (1,4MB/s) and whenever I import those mov files to FCE thez show just fine. but when i add the clips to the timeline (sequence) the quality is cropped - instead of HD i can onlz export the timeline with quicktime conversion and a resolution of 720 x 480. can anybody help me out and tell me how i can export the timeline in full HD quality (as the raw material itself is)?

    Read the article

  • Set Final Cut Express Sequence Options 4:3 to 960p (30fps)

    - by Maccaius
    Hi I have an project in FCE which was recorded in MPEG-4 video in 1280 x 960 (1,4MB/s) and whenever I import those mov files to FCE thez show just fine. but when i add the clips to the timeline (sequence) the quality is cropped - instead of HD i can onlz export the timeline with quicktime conversion and a resolution of 720 x 480. can anybody help me out and tell me how i can export the timeline in full HD quality (as the raw material itself is)? tried the quick setup and exporting as divx and AIC which doesnt reallz work. the actual video size is HD, but qualitz of the video is like SD...

    Read the article

  • Assigning static final int in a JUnit (4.8.1) test suite

    - by Dr. Monkey
    I have a JUnit test class in which I have several static final ints that can be redefined at the top of the tester code to allow some variation in the test values. I have logic in my @BeforeClass method to ensure that the developer has entered values that won't break my tests. I would like to improve variation further by allowing these ints to be set to (sensible) random values in the @BeforeClass method if the developer sets a boolean useRandomValues = true;. I could simply remove the final keyword to allow the random values to overwrite the initialisation values, but I have final there to ensure that these values are not inadvertently changed, as some tests rely on the consistency of these values. Can I use a constructor in a JUnit test class? Eclipse starts putting red underlines everywhere if I try to make my @BeforeClass into a constructor for the test class, and making a separate constructor doesn't seem to allow assignment to these variables (even if I leave them unassigned at their declaration); Is there another way to ensure that any attempt to change these variables after the @BeforeClass method will result in a compile-time error? Can I make something final after it has been initialised?

    Read the article

  • Problems initializing a final variable in Java

    - by froadie
    I keep running into slight variations of a problem in Java and it's starting to get to me, and I can't really think of a proper way to get around it. I have an object property that is final, but dynamic. That is, I want the value to be constant once assigned, but the value can be different each runtime. So I declare the class level variable at the beginning of the class - say private final FILE_NAME;. Then, in the constructor, I assign it a value - say FILE_NAME = buildFileName(); The problem begins when I have code in the buildFileName() method that throws an exception. So I try something like this in the constructor: try{ FILE_NAME = buildFileName(); } catch(Exception e){ ... System.exit(1); } Now I have an error - "The blank final field FILE_NAME may not have been initialized." This is where I start to get slightly annoyed at Java's strict compiler. I know that this won't be a problem because if it gets to the catch the program will exit... But the compiler doesn't know that and so doesn't allow this code. If I try to add a dummy assignment to the catch, I get - "The final field FILE_NAME may already have been assigned." I clearly can't assign a default value before the try-catch because I can only assign to it once. Any ideas...?

    Read the article

  • final transient fields and serialization

    - by doublep
    Is it possible to have final transient fields that are set to any non-default value after serialization in Java? My usecase is a cache variable — that's why it is transient. I also have a habit of making Map fields that won't be changed (i.e. contents of the map is changed, but object itself remains the same) final. However, these attributes seem to be contradictory — while compiler allows such a combination, I cannot have the field set to anything but null after unserialization. I tried the following, without success: simple field initialization (shown in the example): this is what I normally do, but the initialization doesn't seem to happen after unserialization; initialization in constructor (I believe this is semantically the same as above though); assigning the field in readObject() — cannot be done since the field is final. In the example cache is public only for testing. import java.io.*; import java.util.*; public class test { public static void main (String[] args) throws Exception { X x = new X (); System.out.println (x + " " + x.cache); ByteArrayOutputStream buffer = new ByteArrayOutputStream (); new ObjectOutputStream (buffer).writeObject (x); x = (X) new ObjectInputStream (new ByteArrayInputStream (buffer.toByteArray ())).readObject (); System.out.println (x + " " + x.cache); } public static class X implements Serializable { public final transient Map <Object, Object> cache = new HashMap <Object, Object> (); } } Output: test$X@1a46e30 {} test$X@190d11 null

    Read the article

  • Are there any reasons to make all fields and variables final?

    - by Roman
    In my current project I noticed that all class fields and variable inside methods are declared with final modifier whenever it's possible. Just like here: private final XMLStreamWriter _xmlStreamWriter; private final Marshaller _marshaller; private final OutputStream _documentStream; private final OutputStream _stylesStream; private final XMLStreamWriter _stylesStreamWriter; private final StyleMerger _styleMerger; public DocumentWriter(PhysicalPackage physicalPackage) throws IOException { final Package pkg = new Package(physicalPackage); final Part wordDocumentPart = pkg.createPart( "/word/document.xml", "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml", "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument"); // styles.xml final Pair<Part, String> wordStylesPart = wordDocumentPart.createRelatedPart(...); ... } Are there any reasons to do so? p.s. As I know project is not supposed to be multithreaded (at least I've heard nothing about it).

    Read the article

  • How to avoid code repetition initializing final properties?

    - by Hernán Eche
    public class Code{ //many properties //... final String NEWLINE;// ohh a final property! void creation() //this method is for avoid repetition of code { //final initialization can't be put here =( Source= new StringBuffer(); //many other commons new's .. //... } Code() { NEWLINE = System.getProperty("line.separator"); creation(); } Code(String name, int numberr) { NEWLINE = System.getProperty("line.separator"); creation(); name=new Someting(name); number = new Magic(number); } }

    Read the article

  • java serialization and final fields

    - by mdma
    I have an class defining an immutable value type that I now need to serialize. The immutability comes from the final fields which are set in the constructor. I've tried serializing, and it works (surprisingly?) - but I've no idea how. Here's an example of the class public class MyValueType implements Serializable { private final int value; private transient int derivedValue; public MyValueType(int value) { this.value = value; this.derivedValue = derivedValue(value); } // getters etc... } Given that the class doesn't have a no arg constructor, how can it be instantiated and the final field set? (An aside - I noticed this class particularly because IDEA wasn't generating a "no serialVersionUID" inspection warning for this class, yet successfully generated warnings for other classes that I've just made serializable.)

    Read the article

  • Assigning a default value to a final variable in case of an exception in Java

    - by frenetisch applaudierend
    Why won't Java let me assign a value to a final variable in a catch block after setting the value in the try block, even if it is not possible for the final value to be written in case of an exception. Here is an example that demonstrates the problem: public class FooBar { private final int foo; private FooBar() { try { int x = bla(); foo = x; // In case of an exception this line is never reached } catch (Exception ex) { foo = 0; // But the compiler complains // that foo might have been initialized } } private int bla() { // You can use any of the lines below, neither works // throw new RuntimeException(); return 0; } } The problem is not hard to work around, but I would like to understand why the compiler does not accept this. Thanks in advance for any inputs!

    Read the article

  • Final enum in Thread's run() method

    - by portoalet
    Hi, Why is the Elvis elvis definition has to be final to be used inside the Thread run() method? Elvis elvis = Elvis.INSTANCE; // ----> should be final Elvis elvis = Elvis.INSTANCE elvis.sing(4); Thread t1 = new Thread( new Runnable() { @Override public void run() { elvis.sing(6); // --------> elvis has to be final to compile } } ); public enum Elvis { INSTANCE(2); Elvis() { this.x = new AtomicInteger(0); } Elvis(int x){ this.x = new AtomicInteger(x); } private AtomicInteger x = new AtomicInteger(0); public int getX() { return x.get(); } public void setX(int x) {this.x = new AtomicInteger(x);} public void sing(int x) { this.x = new AtomicInteger(x); System.out.println("Elvis singing.." + x); } }

    Read the article

  • Java: startingPath as "public static final" exception

    - by HH
    [Updated] Thanks to polygenelubricants's reply, the real problem is the exception from the method getCanonicalPath() because I cannot include try-catch-loop there. $ cat StartingPath.java import java.util.*; import java.io.*; public class StartingPath { public static final String startingPath = (new File(".")).getCanonicalPath(); public static void main(String[] args){ System.out.println(startingPath); } } $ javac StartingPath.java StartingPath.java:5: unreported exception java.io.IOException; must be caught or declared to be thrown public static final String startingPath = (new File(".")).getCanonicalPath(); ^ 1 error

    Read the article

  • Why is String final in Java?

    - by Alex
    From when I learned that the class java.lang.String is declared as final in Java, I was wondering why is that? I didn't find any answer back then, but this post: How to create a replica of String class in Java? reminded me of my query. Sure, String provides all the functionality I ever needed, and never thought of any operation that would require an extension of class String, but still you'll never know what someone might need! So, does anyone know what was the intent of the designers when they decided to make it final? See also: Why is String a sealed class in C#?

    Read the article

  • final and private static

    - by xdevel2000
    I read that doing: public final void foo() {} is equals to: private static void foo() {} both meaning that the method is not overridable! But I don't see the equivalence if a method is private it's automatically not accessible...

    Read the article

  • Do the ‘up to date’ guarantees for values of Java's final fields extend to indirect references?

    - by mattbh
    The Java language spec defines semantics of final fields in section 17.5: The usage model for final fields is a simple one. Set the final fields for an object in that object's constructor. Do not write a reference to the object being constructed in a place where another thread can see it before the object's constructor is finished. If this is followed, then when the object is seen by another thread, that thread will always see the correctly constructed version of that object's final fields. It will also see versions of any object or array referenced by those final fields that are at least as up-to-date as the final fields are. My question is - does the 'up-to-date' guarantee extend to the contents of nested arrays, and nested objects? An example scenario: Thread A constructs a HashMap of ArrayLists, then assigns the HashMap to final field 'myFinal' in an instance of class 'MyClass' Thread B sees a (non-synchronized) reference to the MyClass instance and reads 'myFinal', and accesses and reads the contents of one of the ArrayLists In this scenario, are the members of the ArrayList as seen by Thread B guaranteed to be at least as up to date as they were when MyClass's constructor completed? I'm looking for clarification of the semantics of the Java Memory Model and language spec, rather than alternative solutions like synchronization. My dream answer would be a yes or no, with a reference to the relevant text.

    Read the article

1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >