### Question:
BeanPath extends SimpleExpression<T> implements Path<T> { @SuppressWarnings("unchecked") public <U extends BeanPath<? extends T>> U as(Class<U> clazz) { try { if (!casts.containsKey(clazz)) { PathMetadata metadata; if (pathMixin.getMetadata().getPathType() != PathType.COLLECTION_ANY) { metadata = PathMetadataFactory.forDelegate(pathMixin); } else { metadata = pathMixin.getMetadata(); } U rv; if (inits != null && pathMixin.getMetadata().getPathType() != PathType.VARIABLE) { rv = clazz.getConstructor(PathMetadata.class, PathInits.class).newInstance(metadata, inits); } else { rv = clazz.getConstructor(PathMetadata.class).newInstance(metadata); } casts.put(clazz, rv); return rv; } else { return (U) casts.get(clazz); } } catch (InstantiationException e) { throw new ExpressionException(e.getMessage(), e); } catch (IllegalAccessException e) { throw new ExpressionException(e.getMessage(), e); } catch (InvocationTargetException e) { throw new ExpressionException(e.getMessage(), e); } catch (NoSuchMethodException e) { throw new ExpressionException(e.getMessage(), e); } } BeanPath(Class<? extends T> type, String variable);  BeanPath(Class<? extends T> type, Path<?> parent,  String property);  BeanPath(Class<? extends T> type, PathMetadata metadata);  BeanPath(Class<? extends T> type, PathMetadata metadata, @Nullable PathInits inits); @Override final R accept(Visitor<R,C> v, C context); @SuppressWarnings("unchecked") U as(Class<U> clazz); @Override PathMetadata getMetadata(); @Override Path<?> getRoot(); BooleanExpression instanceOf(Class<B> type); @SuppressWarnings({ "unchecked", "rawtypes" }) BooleanExpression instanceOfAny(Class... types); @Override AnnotatedElement getAnnotatedElement();  }### Answer:
@Test public void as_path() { SimplePath<BeanPathTest> simplePath = new SimplePath<BeanPathTest>(BeanPathTest.class, "p"); assertNotNull(beanPath.as(simplePath)); }
@Test public void as_class_cached() { MyBeanPath otherPath = beanPath.as(MyBeanPath.class); assertTrue(otherPath == beanPath.as(MyBeanPath.class)); }
@Test @Ignore public void as_class_with_inits() { beanPath = new BeanPath<BeanPathTest>(BeanPathTest.class, PathMetadataFactory.forVariable("p"), PathInits.DEFAULT); MyBeanPath otherPath = beanPath.as(MyBeanPath.class); assertEquals(beanPath, otherPath); }
@Test public void as_class_with_inits_cached() { beanPath = new BeanPath<BeanPathTest>(BeanPathTest.class, PathMetadataFactory.forVariable("p"), PathInits.DEFAULT); MyBeanPath otherPath = beanPath.as(MyBeanPath.class); assertTrue(otherPath == beanPath.as(MyBeanPath.class)); }