Computing desk | ||
---|---|---|
< August 18 | << Jul | August | Sep >> | August 20 > |
Welcome to the Wikipedia Computing Reference Desk Archives |
---|
The page you are currently viewing is an archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages. |
I have an abstract class, one of whose constructors needs to call an abstract method to determine what size of byte array to generate as a PRNG seed. Doing this the obvious way gave me the error "cannot reference this before supertype constructor has been called", and even trying to do it via reflection gave me "cannot reference Object.getClass() before supertype constructor has been called". So I ended up with this very ugly workaround:
private static final HashMap<Class<? extends BaseRNG>, Integer> seedLengthsForClass = new HashMap<>(); private static final Objenesis objenesis = new ObjenesisStd(); private static int getMyNewSeedLength() { try { int stackTraceDepth = 2; StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace(); Class<? extends BaseRNG> clazz; do { clazz = Class.forName(stackTrace[stackTraceDepth].getClassName()); stackTraceDepth++; } while (Modifier.isAbstract(clazz.getModifiers())); Integer seedLength = seedLengthsForClass.get(clazz); if (seedLength == null) { seedLength = objenesis.newInstance(clazz).getNewSeedLength(); seedLengthsForClass.put(clazz, seedLength); } return seedLength; } catch (ClassNotFoundException e) { throw new RuntimeException(e); } } public BaseRNG() { this(DefaultSeedGenerator.getInstance().generateSeed(getMyNewSeedLength())); }
(NB: For those unfamiliar with it, Objenesis is a library that creates instances of a concrete class without running a constructor, using various JVM-specific backdoors.) Are there any better ways to work around this particular error, without requiring all subclasses' constructors to duplicate each other's `super(SEED_ARRAY_SIZE)` call? None of the subclasses have getNewSeedLength()'s output vary between instances, but it does vary according to the subclass. If this isn't evidence that we need abstract static methods, then I'd like to know what would be. NeonMerlin 06:19, 19 August 2017 (UTC)
The middle button of my Logitech G500 mouse can be moved left and right (as well as scroll up and down and be pressed as usual for the MMB). I can't detect my mouse button presses with a keycode scanner but I'm trying to find out what is happening; what signal is being sent to the computer so I can send the same signal via such utilities as AutoHotKey or with a custom Android remote made in the Unified Remote? --145.255.246.8 (talk) 15:20, 19 August 2017 (UTC)
Is there any webside powered by some sort of Watson? Somewhere we I could ask a natural language question like "Is orange a fruit?" and obtain a yes/no answer. The closer I can find is Wolfram Alpha. --Hofhof (talk) 16:53, 19 August 2017 (UTC)
I'm confused as to where to place the question: Here or in Entertanement or in Science. I will try here first.
I am interested in electronic devices (API's) that do music recognition. If you google like I did for "music recognition[1]" (MR) a number of websites come up. I want to know what they all mean. For some MR means lyrics identification and saying: "This is the song which is known as such." I want to define my understanding of music recognition. I think the API should be able to identify all the notes or chords in the piece played be it an operatic aria or a popular song. The music identification in terms of the naming the piece is a sort of a secondary attribute and requires a library.
So, what is the music recognition in all those websites? Thanks, --AboutFace 22 (talk) 22:15, 19 August 2017 (UTC)
Thank you, @The Quixotic Potato. --AboutFace 22 (talk) 12:38, 20 August 2017 (UTC)