instance

Android: two instances of Text-to-Speech work very slowly

流过昼夜 提交于 2019-12-05 07:14:17
I need to implement feature in my Andorind app which allows to play two different synthesized languages in current Acitivity - for instance having two buttons Say English and Say French I've tried to do it in two following ways but both of them works ineffectively because there is long delay before sound plays: first approach: create single instance of TTS and change language by setLocale method depending on what language has to be played. Unfortunately switching between languages by setLocale is time consuming which has impact on reaction after button is clicked second approach: create two

Creating an instance for Class?

孤街醉人 提交于 2019-12-05 06:31:18
Looking at source code of Integer class, just stumble at this below line Class<Integer> TYPE = (Class<Integer>) Class.getPrimitiveClass("int"); And getPrimitiveClass is a native method. static native Class getPrimitiveClass(String name); Why it became a native method ? really want to know. How one can create an instance for Class ?? Does that differs with normal way of creating instance for ex : Ex e = new Ex() ? The comment above the method definition says: /* * Return the Virtual Machine's Class object for the named * primitive type. */ static native Class getPrimitiveClass(String name);

Method accessing protected property of another object of the same class

跟風遠走 提交于 2019-12-05 04:46:06
Should an object's method be able to access a protected property of another object of the same class? I'm coding in PHP, and I just discovered that an object's protected property is allowed to be accessed by a method of the same class even if not of the same object. In the example, at first, you'll get "3" in the output - as function readOtherUser will have successfully accessed the value -, and after that a PHP fatal error will occur - as the main program will have failed accessing the same value. <?php class user { protected $property = 3; public function readOtherUser () { $otherUser = new

Java Reflection get the Instance from a Field

梦想与她 提交于 2019-12-05 03:36:47
is there any way to get the Instance from a Field? Here's a sample code: public class Apple { // ... a bunch of stuffs.. } public class Person { @MyAnnotation(value=123) private Apple apple; } public class AppleList { public add(Apple apple) { //... } } public class Main { public static void main(String args[]) { Person person = new Person(); Field field = person.getClass().getDeclaredField("apple"); // Do some random stuffs with the annotation ... AppleList appleList = new AppleList(); // Now I want to add the "apple" instance into appleList, which I think // that is inside of field.

It looks like I'm instantiating this SpeechAPI interface. How is that possible?

心不动则不痛 提交于 2019-12-05 02:16:41
问题 I am using Microsoft Text-to-Text Speech feature in my project. But I have a question about that, actually not directly about that. So : Normally programmers when creating Interface, they put I as a prefix of the interface name like IReadable,IEnumerator etc. But I've come across something that actually shocked me. in Microsoft Text Speech DLL there is something like this : SpVoice which is interface (they didn't put I as prefix for some reason and I don't know why ?) and SpVoiceClass. So

How to use FacesContext.getCurrentInstance(), it returns null

霸气de小男生 提交于 2019-12-05 01:26:03
I've been struggling for the last couple of days with the login part of my web app. I've gotten to the point where I can succesfully authenticate a user using the JDBCRealm on tomcat(by reading users from a sql server database). Now I want to send some kind of feedback when the user's account has been blocked, or when the credentials are incorrect, this is where I'm stuck now. I wanted to use this: try { request.login(request.getParameter("user"), request.getParameter("pass")); } catch (ServletException se) { FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Wrong Username

Why type(classInstance) is returning 'instance'?

淺唱寂寞╮ 提交于 2019-12-05 01:16:58
I have a method that accepts a parameter that can be of several types, and has to do one thing or other depending on the type, but if I check the type of said parameter, I don't get the 'real' type, I always get <type 'instance'> , and that is messing up with my comparisons. I have something like: from classes import Class1 from classes import Class2 # Both classes are declared in the same file. # I don't know if that can be a problem # # ... # def foo(parameter) if (type(parameter) == type(Class1()): # ... # elif (type(parameter) == type(Class2()): # ... # And as type(parameter) returns <type

Updating Class variable within a instance method

落花浮王杯 提交于 2019-12-05 01:12:31
class MyClass: var1 = 1 def update(value): MyClass.var1 += value def __init__(self,value): self.value = value MyClass.update(value) a = MyClass(1) I'm trying to update a class variable( var1 ) within a method( _ init _ ) but I gives me: TypeError: unbound method update() must be called with MyClass instance as first argument (got int instance instead) I'm doing this because I want easy access to all variables in a class by calling print MyClass.var1 You are confusing classes and instances . class MyClass(object): pass a = MyClass() MyClass is a class, a is an instance of that class. Your error

SPARQL: Get all the entities of subclasses of a certain class

ε祈祈猫儿з 提交于 2019-12-05 00:44:18
I've to get all the instances of a class C and subclasses (direct or indirect) of C, in SPARQL. I can get all the direct subclasses of C in this way: SELECT ?entity WHERE { ?subclass rdfs:subClassOf :C . ?entity rdf:type ?subclass . } But I can't get the instances of an indirect subclass and neither any instance of C. As I know (I've pre-calculated them) all the subclasses (direct and indirect of C), and I can build a dynamic query, is it possible build a query like the following one? SELECT ?entity WHERE { ?entity rdf:type in <list>. } Thanks to everyone. EDIT: I've just solved it, even if in

Is an instance of a class automatically created when you first call a static method

二次信任 提交于 2019-12-04 22:47:12
I would like to know if you have a class with only static methods in it, does an actual instance of the class get created somewhere when you call 1st static method? This is somewhat confusing to understand in terms of memory management as you never actually call the constructor or create an instance of the method explicitly. If an instance does get created, I would like to better understand where this instance lives and for how long. No. Calling a static method does not require (or create) an instance of a class . See also JLS-8.4.3.2 static methods which says (in part) A method that is