class

How should i use a jar file?

≯℡__Kan透↙ 提交于 2019-12-24 21:48:44
问题 I have a jar file which contains some classes those which i want to use in my project. I am working in command line and not in eclipse. Please tell me how i should use those classes in the jar file for my project. 回答1: Use the -classpath command line option: javac -classpath library.jar MyProgram.java And then to run it, specify the classpath again - including where your actual code is: java -classpath library.jar;. MyProgram (That's assuming you're using Windows. On Unix use : instead of ;

Initializing a variable using default constructor [duplicate]

风流意气都作罢 提交于 2019-12-24 21:06:20
问题 This question already has answers here : Default constructor with empty brackets (9 answers) Closed 4 years ago . I'm pretty new to c++, i'm now trying to learn all the basics, I know when default constructors are called, but when i tried different syntax it doesn't work like i expected. Look at the following code: class a; class b(); class c(NULL); 'class' is a class i created with default constructor, for a and c everything works well, but for b it just won't recognize the variable as a

how to create in best way an instance from the class object

余生颓废 提交于 2019-12-24 21:04:46
问题 There is a way to avoid the slow reflection to create an instance from a class, obviously within another method ? For example: Foo foo = new Foo(); foo.create(Dog.class, "rocky"); class Foo { Object create(Class object, String dogName) { //create an instance of the class 'object' here passing the argument to constructor //e.g. Object obj = new object(dogName); <-- this is wrong return obj; } } class Dog extends Animal { Dog(String dogName) { this.name = dogName; } } class Animal { String name

How to reduce the usage of IF - ELSE by reflection ? Can I get the code example

情到浓时终转凉″ 提交于 2019-12-24 21:02:53
问题 I was trying to use reflection for the code of PizzaFactory Class so that I can remove the if else condition and make my code more dynamic. But I am not able to figure out how. Pizza.java package PizzaTrail; import java.util.List; //this is the main abstract factory which will be extended by the concrete factory public abstract class Pizza { public abstract List fetchIngredients(String Type); } PizzaFactory.java package PizzaTrail; import java.util.List; //this is the concrete factory public

Binding the same interface twice (Guice)

我与影子孤独终老i 提交于 2019-12-24 20:34:22
问题 My classes (let call them X and Y ) both implementing Parser interface do (relatively) CPU intensive operations to build parsers for certain syntaxes (different syntaxes for X and Y ). Now I want to inject (with Guice) dependencies of both X and Y into constructor of an (upper level) parser P . Both arguments of P should be of the type Parser : class P implements Parser { @Inject public P(Parser x, Parser y) { // ... } } How can I make Guice to differentiate which of the two arguments of P

Return a class, not an instance, of a concrete class that extends an abstract base class?

拈花ヽ惹草 提交于 2019-12-24 20:34:16
问题 If I have a class hierarchy like this AbstractSuperClass ConcreteClassA ConcreteClassB is it possible to have a static method in AbstractSuperClass which returns the class - not an instance - of one of the two concrete classes? I've tried returning Class<AbstractSuperClass> , but the IDE (Android Studio) says Incompatible types. Required: Class <com.example.AbstractSuperClass> Found: Class <com.example.ConcreteClassA> Here's an example of what I'm thinking, but which isn't working: public

Changing parent Div background color on active tab

≯℡__Kan透↙ 提交于 2019-12-24 20:22:58
问题 I am trying to figure out how to change the parent div container background color when clicking a tab. I want to have it so that when a tab is active it adds a class to the parent div. Each active tab would add different bg color to the parent. Link to the example This is what I would like to do. 回答1: I tried it in your console, check this var colors = ["red", "black", "yellow"]; jQuery(document).ready(function() { jQuery(".vc_tta-tabs-list > li").on("click", function() { jQuery(".grve

howto let ruby share data beetwen a class and its subclasses in conjuction with extend

假装没事ソ 提交于 2019-12-24 20:19:27
问题 module M def f=(x) @f= x end def f @f end end class A extend M end class B < A end A.f= 42 puts A.f puts B.f this produces 42 nil Is @f a class variable to A and B? How do I share a variable between A and B by only writing this into M? 回答1: By not using @@f directly, but rather class_variable_set() and class_variable_get(), class variables of A, B and C can be used from within M. module M def f=(x) class_variable_set("@@f", x) end def f class_variable_get("@@f") end end class A extend M end

Untangling Inherited Methods

£可爱£侵袭症+ 提交于 2019-12-24 20:13:17
问题 Okay, so this is my first time implementing classes, and everything's going wrong. I'm implimenting a different class, PhraseGenerator, and the method inherited which I wish to define here is getPhrase(). It needs to return theArcha. Instead of working within it, I chose to wrap its braces around my work afterwards, and now, no matter where I put it, a different error arises. Before dealing with any of these, I want to make sure I'm putting it in the right place. To my understanding, it would

php __autoload() and dynamic / runtime class definition - is there a way without eval?

我的未来我决定 提交于 2019-12-24 19:50:26
问题 I read this post after doing a search for related posts. I have a slightly different, but related problem. Is there a way WITHOUT EVAL() (because this is a bad idea - open for abuse if someone allows a user to supply the value that is used in eval, etc) such that you can define the structure of the class, for example: if(!class_exists($className) && dao::tableExists($className)) { class $className extends daoObject { public function __construct($uid) { parent::__construct($uid); } } dao: