instantiation

Java array substring

强颜欢笑 提交于 2019-12-04 02:44:31
How can I create/instantiate an array to be equal to the substring of another array, where the size of the substring is unknown: int n; //some number derived somewhere else String[] grp = elements[i] to elements[i+n]; Use Arrays.copyOfRange : public static <T> T[] copyOfRange(T[] original, int from, int to) Copies the specified range of the specified array into a new array. The initial index of the range ( from ) must lie between zero and original.length , inclusive. The value at original[from] is placed into the initial element of the copy (unless from == original.length or from == to ).

JSF application scope instantiation and injection

我怕爱的太早我们不能终老 提交于 2019-12-04 02:16:52
Probably my question is a trivial one, but I never used an application scope bean before. I need the application bean because I have to do time consuming transactions on the database. my search didn't satisfy my curiosity at all. I don't know why but I didn't manage to initialize the bean (it is null) or it the app crashed. So I have an application scope bean @ManagedBean(eager=true) @ApplicationScoped public class ApplicationContainer { ... } eager=true I read that tells JSF to initiate the bean every time when the application server (I use GlassFish) is started. I read in several places that

newInstance() with inner classes

纵然是瞬间 提交于 2019-12-03 18:03:29
问题 I've been working on an instantiation method that will allow me to package a variety of similar classes into one outer class. I could then instantiate each unique class type by passing the name of that type to the constructor. After a lot of research and errors, this is what I have come up with. I have left an error, to demonstrate my question. import java.lang.reflect.Constructor; public class NewTest { public static void main(String[] args) { try { Class toRun = Class.forName("NewTest$" +

DDD - Aggregate Root - Example Order and OrderLine

荒凉一梦 提交于 2019-12-03 13:26:23
I am trying to get my hands dirty learning DDD (by developing a sample eCommerce site with entities like Order , OrderLines , Product , Categories etc). From what I could perceive about Aggregate Root concept I thought Order class should be an aggregate root for OrderLine . Things went fine so far, however I am confused when it define a create order flow from UI. When I want to add an order line to my order object, how should I get/create an instance of an OrderLine object: Should I hardcode the new OrderLine() statement in my UI/Service class Should I define a method with parameters like

Declare an object even before that class is created

醉酒当歌 提交于 2019-12-03 12:55:36
问题 Is there anyway to declare an object of a class before the class is created in C++? I ask because I am trying to use two classes, the first needs to have an instance of the second class within it, but the second class also contains an instance of the first class. I realize that you may think I might get into an infinite loop, but I actually need to create and instance of the second class before the first class. 回答1: You can't do something like this: class A { B b; }; class B { A a; }; The

non-deferred static member initialization for templates in gcc?

旧街凉风 提交于 2019-12-03 12:27:28
问题 Does gcc have any guarantees about static member initialization timing, especially regarding template classes? I want to know if I can get a hard guarantee that static members ( PWrap_T<T>::p_s ) will be initialized before main() , when classes are instantiated across multiple compilation units. It isn't practical to try to manually touch a symbol from each compilation unit at the start of main, but it isn't clear to me that anything else would work. I've tested with methods like bar() in

Create instance of class known at runtime in Swift

╄→гoц情女王★ 提交于 2019-12-03 12:05:51
A picture is worth a thousand words, how to rewrite this code from Objective-C to Swift? - (id) instanceOfClass: (Class) class withInitializer: (SEL) initializerSelector withObject: (id) object { id obj = nil; if([class instancesRespondToSelector:initializerSelector]) { obj = [[class alloc] performSelector:initializerSelector withObject:object]; } return obj; } id myViewController = [self instanceOfClass:[ViewController class] withInitializer:@selector(initWithObject:) withObject:@"super-string!"]; NSLog(@"%@", myViewController); This cannot be done purely in Swift. You can only do this by

PHP: How to instantiate a class with arguments from within another class

孤人 提交于 2019-12-03 10:59:31
I am in a situations where i need to instantiate a class with arguments from within an instance of another class. Here is the prototype: //test.php class test { function __construct($a, $b, $c) { echo $a . '<br />'; echo $b . '<br />'; echo $c . '<br />'; } } Now, i need to instantiate above class using below class's cls function: class myclass { function cls($file_name, $args = array()) { include $file_name . ".php"; if (isset($args)) { // this is where the problem might be, i need to pass as many arguments as test class has. $class_instance = new $file_name($args); } else { $class_instance =

instantiate chrome object in powershell

∥☆過路亽.° 提交于 2019-12-03 06:51:34
问题 I have a powershell script which works just fine in IE however I need to also have it work in Chrome. $ie = new-object -com "InternetExplorer.Application" Works fine for IE. How do I instantiate the Chrome browser? 回答1: You can start a process by name and even pass it a parameter, like this: Start-Process "chrome.exe" "www.google.com" 回答2: if you are fine with a 3rd party dll you could use Selenium which has also a Chromdriver, that gives you the same kind of control over Chrome as through

Conditional instantiation of verilog module

岁酱吖の 提交于 2019-12-03 06:47:23
Is it possible to instantiate a module conditionally in verliog ? example : if (en==1) then module1 instantiation else module2 instantiation From IEEE Std 1364-2001 : 12.1.3.3 generate-conditional A generate-conditional is an if-else-if generate construct that permits modules, user defined primitives, Verilog gate primitives, continuous assignments, initial blocks and always blocks to be conditionally instantiated into another module based on an expression that is deterministic at the time the design is elaborated. example given in LRM : module multiplier(a,b,product); parameter a_width = 8, b